1 (edited by kevinferm 2012-02-28 21:06)

Topic: Wordpress to PunBB post integration

Alright, so I found a post which allowed me to do SOME post integration wordpress->punbb where if I posted something on wordpress it would then go on to the forums.

This is the code I'm using for the posting part

function punbb_publish_post($id)
    {
    global $wpdb;
    $wppost = $wpdb->get_row("SELECT ID, post_date, post_title, post_content FROM ".$wpdb->posts." WHERE ID = ".$id." LIMIT 1");
    /* Check if edited or new */
    $wppost_check = $wpdb->get_row("SELECT id, topic_id FROM ".PUNPREFIX."posts WHERE poster = 'Admin' AND posted = ".strtotime($wppost->post_date));
    if($wppost_check)
    {
    
    $wpdb->query("UPDATE ".PUNPREFIX."topics SET subject = '".$wppost->post_title."' WHERE id = ".$wppost_check->topic_id);
    $wpdb->query("UPDATE ".PUNPREFIX."posts SET message = '".$wppost->post_content."' WHERE id = ".$wppost_check->id);
    
    }
    /*If New */
    else {
    $wpdb->query("INSERT INTO ".PUNPREFIX."topics (poster, subject, posted, last_post, last_poster, forum_id) VALUES(
    'Neteyes',
    '".$wppost->post_title."',
    ".strtotime($wppost->post_date).",
    ".strtotime($wppost->post_date).",
    'Neteyes',
    1)");
    $topic_id = $wpdb->insert_id;
    
    $wpdb->query("INSERT INTO ".PUNPREFIX."posts (poster, poster_id, message, posted, topic_id, poster_ip) VALUES(
    'Neteyes',
    2,
    '".$wppost->post_content."',
    ".strtotime($wppost->post_date).",
    ".$topic_id.",
    '192.168.0.1'
    )");
    $post_id = $wpdb->insert_id;
    
    $wpdb->query("UPDATE ".PUNPREFIX."topics SET last_post_id = ".$post_id.", first_post_id = ".$post_id." WHERE id = ".$topic_id);
    $wpdb->query("UPDATE ".PUNPREFIX."forums SET last_post = ".strtotime($wppost->post_date).", last_post_id = ".$post_id.", last_poster = 'Neteyes' WHERE id = 1");
    $punbb_postnumber = $wpdb->get_row("SELECT num_posts, username FROM ".PUNPREFIX."users WHERE username = 'Neteyes' LIMIT 1");
    $wpdb->query("UPDATE ".PUNPREFIX."users SET num_posts = ".$punbb_postnumber->num_posts."+1 WHERE username = 'Neteyes'");
    
    /* Puts a Link to the forum topic in the post */
    $wp_add = "<p>Diskutiere <a href=\"/\" title=\"Link zum Topic im Forum\">hier. -></a></p>";
    $wp_content = $wppost->post_content.$wp_add;
    }
    }

I might have some of the usernames wrong, I'm not sure.
The thing is it's not giving me any errors but it's not posting anything on the forums either.

I added the

do_action('punbb_publish_post', $id, $post);

below

    do_action('edit_post', $post_id, $post);
    do_action('save_post', $post_id, $post);
    do_action('wp_insert_post', $post_id, $post);

again, I'm not sure if the variables there are totally correct but it's not giving me any errors.

The file I'm editing is wp-includes/post.php

[EDIT] This script is also from PunBB 1.3 so it's probably somewhat outdated.

Re: Wordpress to PunBB post integration

Kevinferm,

This scriptworks for you ?
Can we see the result on a website ? smile

Thanks. wink

Benoît V.
My Board