Esempio n. 1
0
function onaction_comment_notify($commentID)
{
    global $wpdb;
    $status = $wpdb->get_var("SELECT comment_approved FROM {$wpdb->comments} WHERE comment_ID = {$commentID}");
    $post_id = $wpdb->get_var("SELECT comment_post_ID FROM {$wpdb->comments} WHERE comment_ID = {$commentID}");
    if ($status == 1) {
        do_CommentNotifications($commentID, $post_id);
    } else {
        do_CommentWaiting($commentID, $post_id);
    }
}
Esempio n. 2
0
function d3forum_sync_to_wp_comment($mode, $link_id, $forum_id, $topic_id, $post_id = 0)
{
    global $xpress_config, $xoops_db, $wpdb, $blog_id;
    if (!is_d3forum_setting()) {
        die('The setting of the D3Forum comment integration is wrong. ');
    }
    if (empty($blog_id)) {
        $blog_id = 1;
    }
    $d3f_forum_id = $xpress_config->d3forum_forum_id;
    $d3forum_prefix = get_xoops_prefix() . $xpress_config->d3forum_module_dir . '_';
    $xpress_prefix = get_wp_prefix();
    $wp_comments = $wpdb->comments;
    $wp_posts = $wpdb->posts;
    $wp_d3forum_link = $xpress_prefix . 'd3forum_link';
    $d3f_posts = $d3forum_prefix . 'posts';
    $d3f_topics = $d3forum_prefix . 'topics';
    $d3f_users2topics = $d3forum_prefix . 'users2topics';
    $d3f_post_votes = $d3forum_prefix . 'post_votes';
    $db_xoops_users = get_xoops_prefix() . 'users';
    $comment_post_ID = $link_id;
    $d3f_sql = "SELECT {$d3f_posts}.guest_name, ";
    $d3f_sql .= "{$d3f_posts}.guest_email, {$d3f_posts}.guest_url, {$d3f_posts}.poster_ip, {$d3f_posts}.post_time, ";
    $d3f_sql .= "{$d3f_posts}.post_text, {$d3f_posts}.approval, {$d3f_posts}.uid ,{$d3f_posts}.pid ";
    $d3f_sql .= "FROM {$d3f_posts} ";
    $d3f_sql .= "WHERE {$d3f_posts}.post_id = {$post_id}";
    $d3f_row = $xoops_db->get_row($d3f_sql);
    if (empty($d3f_row)) {
        die('...Err. OPEN D3Forum Data (' . $d3f_sql . ')');
    }
    $uid = $d3f_row->uid;
    if (!empty($uid)) {
        $xu_sql = "SELECT uid ,name ,uname ,email , url FROM {$db_xoops_users} WHERE uid = {$uid}";
        $xu_row = $xoops_db->get_row($xu_sql);
        if (empty($xu_row)) {
            $user_display_name = '';
        } else {
            if (empty($xu_row->name)) {
                $user_display_name = $xu_row->uname;
            } else {
                $user_display_name = $xu_row->name;
            }
            $comment_author_email = "'" . $xu_row->email . "'";
            $comment_author_url = "'" . $xu_row->url . "'";
        }
        $comment_author = "'" . addSlashes($user_display_name) . "'";
    } else {
        $comment_author = "'" . addSlashes($d3f_row->guest_name) . "'";
        $comment_author_email = "'" . $d3f_row->guest_email . "'";
        $comment_author_url = "'" . $d3f_row->guest_url . "'";
    }
    $comment_author_IP = "'" . $d3f_row->poster_ip . "'";
    $gmt_offset = get_option('gmt_offset');
    $local_timestamp = $d3f_row->post_time + $gmt_offset * 3600;
    $comment_date = "'" . date('Y-m-d H:i:s', $local_timestamp) . "'";
    $comment_content = "'" . addSlashes($d3f_row->post_text) . "'";
    $comment_approved = "'" . $d3f_row->approval . "'";
    $user_ID = $d3f_row->uid;
    $comment_date_gmt = "'" . gmdate('Y-m-d H:i:s', $d3f_row->post_time) . "'";
    $comment_type = '';
    if ($d3f_row->pid > 0) {
        $comment_parent = get_wp_comment_ID($d3f_row->pid);
    } else {
        $comment_parent = 0;
    }
    switch ($mode) {
        case 'reply':
        case 'newtopic':
            $wp_sql = "INSERT INTO {$wp_comments} ";
            $wp_sql .= "(comment_post_ID , comment_author , comment_author_email , comment_author_url , comment_author_IP , ";
            $wp_sql .= "comment_date , comment_content , comment_approved , user_id , comment_date_gmt, comment_parent) ";
            $wp_sql .= "VALUES ";
            $wp_sql .= "({$comment_post_ID}, {$comment_author}, {$comment_author_email}, {$comment_author_url}, {$comment_author_IP}, ";
            $wp_sql .= "{$comment_date}, {$comment_content}, {$comment_approved}, {$user_ID}, {$comment_date_gmt}, {$comment_parent})";
            $wp_res = $xoops_db->query($wp_sql);
            if ($wp_res === false) {
                die('...Err. INSERT' . $wp_comments . '(' . $wp_sql . ')');
            }
            $comment_ID = mysql_insert_id();
            $wp_sql = "UPDATE {$wp_posts} SET  comment_count = comment_count +1 WHERE ID = {$comment_post_ID}";
            $xoops_db->query($wp_sql);
            $wp_sql = "INSERT INTO {$wp_d3forum_link} ";
            $wp_sql .= "(comment_ID , post_id, wp_post_ID, forum_id, blog_id) ";
            $wp_sql .= "VALUES ";
            $wp_sql .= "({$comment_ID}, {$post_id}, {$link_id}, {$d3f_forum_id}, {$blog_id})";
            $xoops_db->query($wp_sql);
            if ($comment_approved == 0) {
                do_CommentWaiting($comment_ID, $post_id);
            }
            break;
        case 'edit':
            $comment_ID = "SELECT comment_ID FROM {$wp_d3forum_link} WHERE post_id = {$post_id}";
            $comment_ID = $xoops_db->get_var("SELECT comment_ID FROM {$wp_d3forum_link} WHERE post_id = {$post_id}");
            if (empty($comment_ID)) {
                die('...Err. EDIT' . $wp_comments . '(' . $wp_sql . ')');
            }
            $wp_sql = "UPDATE {$wp_comments} SET comment_content = {$comment_content} , comment_date_gmt = {$comment_date_gmt} WHERE comment_ID = {$comment_ID}";
            $wp_res = $xoops_db->query($wp_sql);
            if (empty($wp_res)) {
                die('...Err. UPDATE' . $wp_comments . '(' . $wp_sql . ')');
            }
            break;
        case 'delete':
            // wordpress comments delete
            $comment_ID = get_wp_comment_ID($post_id);
            if ($comment_ID > 0) {
                $sql = "SELECT comment_type FROM {$wp_comments} WHERE comment_ID = {$comment_ID}";
                $comment_type = $xoops_db->get_var("SELECT comment_type FROM {$wp_comments} WHERE comment_ID = {$comment_ID}");
                if (!empty($comment_type)) {
                    break;
                }
                $xoops_db->query("DELETE FROM {$wp_comments} WHERE comment_ID = {$comment_ID}");
                $xoops_db->query("DELETE FROM {$wp_d3forum_link} WHERE post_id = {$post_id}");
                $xoops_db->query("UPDATE {$wp_posts} SET  comment_count = comment_count -1 WHERE ID = {$comment_post_ID}");
            }
            break;
        default:
    }
    return true;
}