Changeset 106 for trunk/wp-content
- Timestamp:
- Mar 14, 2009, 11:27:03 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-content/plugins/xpressme/include/d3forum_comment_synchro.php
r105 r106 569 569 switch($mode){ 570 570 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); 574 573 // approval 575 574 if( $approval ) { … … 593 592 $sql = "UPDATE ".$d3f_posts." SET $set4sql WHERE post_id=$edit_post_id"; 594 593 $xoops_db->query($sql); 595 if( ! $xoops_db->query($sql) ) die( "DB ERROR IN UPDATE post") ;594 $xoops_db->query($sql) ; 596 595 if ($edit_post_pid == 0){ 597 596 $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); 599 598 } 600 599 wp_d3forum_sync_topic( $d3forum_dirname , $topic_id , true , ! $edit_post_pid ) ; … … 620 619 // create post under specified post_id 621 620 $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) ; 623 622 $post_id = mysql_insert_id(); 624 623 wp_d3forum_sync_topic( $d3forum_dirname , $topic_id ) ; … … 653 652 // create topic and get a new topic_id 654 653 $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) ; 656 655 $topic_id = mysql_insert_id(); 657 656 // create post in the topic 658 657 $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) ; 660 659 $post_id = mysql_insert_id(); 661 660 wp_d3forum_sync_topic( $d3forum_dirname , $topic_id , true , true ) ; … … 697 696 function wp_d3forum_delete_post_recursive( $d3forum_dirname , $post_id ,$isChild = false) 698 697 { 699 $post_id = intval( $post_id ) ; 698 $post_id = intval( $post_id ) ; // post_id is d3forum post(comments) id. 700 699 global $XPressME,$xoops_db; 701 700 $d3forum_prefix = get_xoops_prefix() . $d3forum_dirname . '_'; 702 701 $xpress_prefix = get_wp_prefix(); 703 702 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. 704 706 $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 } 716 711 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" ) ; 719 714 720 715 $wp_comments = $xpress_prefix . 'comments'; … … 722 717 $wp_d3forum_link = $xpress_prefix . 'd3forum_link'; 723 718 724 $comment_ID = get_wp_comment_ID($post_id); 719 $comment_ID = get_wp_comment_ID($post_id); // get wordpress comment ID 725 720 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"); 729 722 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"); 732 724 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"); 739 729 } 740 730 } … … 752 742 // delete posts 753 743 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 } 759 749 } 760 750 } … … 763 753 764 754 // 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" ); 767 756 // 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" ); 769 758 } 770 759 … … 780 769 $topic_id = intval( $topic_id ) ; 781 770 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"); 785 772 786 773 // 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"); 789 775 790 776 // get last_post_id and total_posts 791 777 $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); 793 779 $last_post_id = $row->last_post_id; 794 780 $total_posts = $row->total_posts; … … 812 798 $topictitle4set = $sync_topic_title ? "topic_title='".addslashes($first_subject)."'," : "" ; 813 799 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" ); 815 801 816 802 // rebuild tree informations … … 899 885 $posts_count = $row->posts_count; 900 886 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" ) ; 902 888 903 889 if( $sync_also_category ) return wp_d3forum_sync_category( $d3forum_dirname , $cat_id ) ; … … 905 891 } 906 892 893 function 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 907 912 // store redundant informations to a category from its forums 908 913 function wp_d3forum_sync_category( $d3forum_dirname , $cat_id ) … … 914 919 915 920 // 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 ) ; 919 922 $children[] = $cat_id ; 920 923 $children = array_map( 'intval' , $children ) ; … … 937 940 938 941 // 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" ); 940 943 941 944 // do sync parents … … 972 975 } 973 976 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 ) )."'" ) ; 975 978 } 976 979
Note: See TracChangeset
for help on using the changeset viewer.