- Timestamp:
- Mar 14, 2009, 12:40:43 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-content/plugins/xpressme/include/d3forum_comment_synchro.php
r104 r105 31 31 { 32 32 global $wpdb; 33 $comment_type = $wpdb->get_var("SELECT comment_type FROM $wpdb->comments WHERE comment_ID = $comment ID");33 $comment_type = $wpdb->get_var("SELECT comment_type FROM $wpdb->comments WHERE comment_ID = $comment_ID"); 34 34 if (!empty($comment_type)) return ; 35 35 return wp_comment_sync_to_d3forum($comment_ID,'post'); … … 38 38 { 39 39 global $wpdb; 40 $comment_type = $wpdb->get_var("SELECT comment_type FROM $wpdb->comments WHERE comment_ID = $comment ID");40 $comment_type = $wpdb->get_var("SELECT comment_type FROM $wpdb->comments WHERE comment_ID = $comment_ID"); 41 41 if (!empty($comment_type)) return ; 42 42 return wp_comment_sync_to_d3forum($comment_ID,'edit'); … … 45 45 { 46 46 global $wpdb; 47 $comment_type = $wpdb->get_var("SELECT comment_type FROM $wpdb->comments WHERE comment_ID = $comment ID");47 $comment_type = $wpdb->get_var("SELECT comment_type FROM $wpdb->comments WHERE comment_ID = $comment_ID"); 48 48 if (!empty($comment_type)) return ; 49 49 return wp_comment_sync_to_d3forum($comment_ID,'delete'); … … 66 66 } 67 67 68 function onaction_comment_apobe($comment ID){68 function onaction_comment_apobe($comment_ID){ 69 69 global $wpdb; 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");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"); 72 72 if(is_null($status)) return; 73 // $status = wp_get_comment_status($comment ID);73 // $status = wp_get_comment_status($comment_ID); 74 74 switch($status){ 75 75 case 'approved': 76 76 case 1: 77 if (empty($comment_type)) onaction_edit_comment($comment ID);77 if (empty($comment_type)) onaction_edit_comment($comment_ID); 78 78 break; 79 79 case 'unapproved': 80 80 case 0: 81 if (empty($comment_type)) onaction_edit_comment($comment ID);81 if (empty($comment_type)) onaction_edit_comment($comment_ID); 82 82 break; 83 83 default: … … 490 490 $forum_id = $d3f_forum_id; 491 491 $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 493 493 $topic_title = 'Re.' . addSlashes($row->post_title); 494 494 $post_time = strtotime($row->comment_date); // or $row2['comment_date_gmt'] … … 513 513 if (empty($topic_id)) return; 514 514 }else{ 515 // Does the first comment (= topic) on the post exist? 515 516 $sql = "SELECT * FROM $d3f_topic WHERE topic_external_link_id = $topic_external_link_id AND forum_id = $forum_id"; 516 517 $row = $xoops_db->get_row($sql) ; 518 $topic_first_post_id = $row->topic_first_post_id; 517 519 if (empty($row)){ 518 520 $mode = $mode = 'newtopic'; 519 521 } else { 520 522 $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 522 525 $row = $xoops_db->get_row("SELECT * FROM $wp_d3forum_link WHERE comment_ID = $comment_ID") ; 526 523 527 if (!empty($row)){ 524 528 $mode = $mode = 'edit'; … … 531 535 } 532 536 if ($reply_pid == 0) { 533 $reply_pid = $ row->topic_first_post_id; //reply_first_comment537 $reply_pid = $topic_first_post_id; //reply_first_comment 534 538 } 535 539 } … … 624 628 $wp_sql .= "VALUES "; 625 629 $wp_sql .= "($comment_ID, $post_id)"; 626 $xoops_db->query($ sql);630 $xoops_db->query($wp_sql); 627 631 628 632 break; … … 661 665 $wp_sql .= "VALUES "; 662 666 $wp_sql .= "($comment_ID, $post_id, $topic_external_link_id)"; 663 $xoops_db->query($ sql);667 $xoops_db->query($wp_sql); 664 668 665 669 break; … … 750 754 $sql = "SELECT post_id FROM ".$d3forum_prefix."posts WHERE topic_id=$topic_id" ; 751 755 $posts = $xoops_db->query($sql); 752 if( empty($posts)) die( _MD_D3FORUM_ERR_SQL.__LINE__ ) ;756 if( empty($posts)) die( 'SQL ERROR '.__LINE__ ) ; 753 757 foreach($posts as $post){ 754 758 wp_d3forum_delete_post_recursive( $d3forum_dirname , $post->post_id ) ; … … 759 763 760 764 // 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__ ) ; 762 766 763 767 // 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__ ) ; 765 769 } 766 770 … … 777 781 778 782 $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 781 785 782 786 // get first_post_id 783 787 $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" ) ; 786 789 787 790 // 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; 791 795 792 796 if( empty( $total_posts ) ) { … … 797 801 798 802 // 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; 802 811 // sync topic_title same as first post's subject if specified 803 812 $topictitle4set = $sync_topic_title ? "topic_title='".addslashes($first_subject)."'," : "" ; 804 813 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__ ) ; 806 815 807 816 // 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 ; 816 829 } 817 830 … … 828 841 $new_post_ids = array() ; 829 842 $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; 831 846 $new_post_ids[ intval( $new_post_id ) ] = $new_unique_path ; 832 847 if( ! empty( $new_unique_path ) ) { … … 857 872 return $parray ; 858 873 } 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; 860 877 $parray = wp_d3forum_makecattree_recursive( $tablename , $new_cat_id , $order , $parray , $depth + 1 , $new_cat_title ) ; 861 878 } … … 873 890 874 891 $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__ ) ; 883 902 884 903 if( $sync_also_category ) return wp_d3forum_sync_category( $d3forum_dirname , $cat_id ) ; … … 902 921 903 922 // 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 ; 907 929 908 930 // 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 ; 912 937 913 938 // 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__ ) ; 915 940 916 941 // 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" ) ; 918 943 if( $pid != $cat_id && $pid > 0 ) { 919 944 wp_d3forum_sync_category( $d3forum_dirname , $pid ) ; … … 941 966 942 967 // 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 ) ) { 946 970 $old_data = unserialize( $old_data_serialized ) ; 947 971 if( $old_data == $data ) return ;
Note: See TracChangeset
for help on using the changeset viewer.