1

Topic: Wordpress2PunBB Posting

At the moment I am working on making a wordpress plugin to post every post on wordpress to a foren topic..
but is doesn't worked right now, may you can help.

    global $wpdb;
    $wppost = $wpdb->get_row("SELECT post_date, post_title, post_content FROM ".$wpdb->posts." WHERE ID = ".$id." LIMIT 1");
    
    $post_info = array(     "poster" => "Jones",
                            "subject" => "".$wppost->post_title."",
                            "posted" => "".strtotime($wppost->post_date)."",
                            "forum_id" => 1,
                            "poster_id" => 2,
                            "message" => "".$wppost->post_content);
    require ("../punbb/include/functions.php");
    add_topic($post_info);

Thats the section I am using to get the topic made but nothing happen.

Re: Wordpress2PunBB Posting

i need a extension that work as comments from wordpress.

Re: Wordpress2PunBB Posting

Seems like PunBB functions can't work with database if one just includes functions.php.

Try to include PunBB functions this way (as it's described in Wiki):

define('FORUM_ROOT', '../punbb/');
require FORUM_ROOT.'include/common.php';

functions.php will be included automatically.

4

Re: Wordpress2PunBB Posting

Well then I just get a blank page, and no topic created.
changed code now to

    global $wpdb;
    $wppost = $wpdb->get_row("SELECT post_date, post_title, post_content FROM ".$wpdb->posts." WHERE ID = ".$id." LIMIT 1");
    
    $post_info = array(     "poster" => "Jones",
                            "subject" => "".$wppost->post_title."",
                            "posted" => "".strtotime($wppost->post_date)."",
                            "forum_id" => 1,
                            "poster_id" => 2,
                            "message" => "".$wppost->post_content);
// Add these lines in the very top of your code
define('FORUM_ROOT', '../punbb/');
require FORUM_ROOT.'include/common.php';

    add_topic($post_info);

Re: Wordpress2PunBB Posting

Any error messages? Try to add

error_reporting(E_ALL);

while debugging.

6

Re: Wordpress2PunBB Posting

Added ..

Code now

    global $wpdb;
    $wppost = $wpdb->get_row("SELECT post_date, post_title, post_content FROM ".$wpdb->posts." WHERE ID = ".$id." LIMIT 1");
    
    $post_info = array(     "poster" => "Jones",
                            "subject" => "".$wppost->post_title."",
                            "posted" => "".strtotime($wppost->post_date)."",
                            "forum_id" => 1,
                            "poster_id" => 2,
                            "message" => "".$wppost->post_content);
    // Add these lines in the very top of your code
    define('FORUM_ROOT', '../punbb/');
    require FORUM_ROOT.'include/common.php';

    add_topic($post_info);
    error_reporting(E_ALL);

Still blank page and nothing happen.

Re: Wordpress2PunBB Posting

Oh, sorry. I've forgotten to tell you to put error_reporting(E_ALL); at the beginning of the file.

8

Re: Wordpress2PunBB Posting

Urm stupid me, forgot it either wink
To many problems that need to get fixed in a short time wink
My community waits for a forum wink

Getting the following error.

Fatal error: Cannot redeclare validate_username() (previously declared in D:\xampplite\htdocs\punbb\wp-includes\registration.php:49) in D:\xampplite\htdocs\punbb\punbb\include\functions.php on line 864

Re: Wordpress2PunBB Posting

There are functions with the same names in Wordpress and PunBB.

Try to do the next steps.

1. Copy include/essentials.php to include/my_essentials.php.
2. Copy include/functions.php to include/my_functions.php.
3. Change the filename in include/my_essentials.php from functions.php to my_functions.php (line 22):

// Load the functions script
require FORUM_ROOT.'include/my_functions.php';

4. Edit your script like this (I've just successfully tested it)

<?php

    error_reporting(E_ALL);
    define('FORUM_DEBUG', 1);

    $post_info = array(
        "poster" => "Jones",
        "subject" => "test",
        "posted" => time(),
        "forum_id" => 1,
        "poster_id" => 2,
        "message" => "test",
        'is_guest' => false,
        'subscribe' => false,
        'hide_smilies' => 0,
    );

    define('FORUM_ROOT', './');
    require FORUM_ROOT.'include/my_essentials.php';

    add_topic($post_info, $a, $b);

5. Try to run the script. Look through error messages. Remove from my_functions.php all functions with names conflicted.

10 (edited by Jones 2010-04-20 13:31)

Re: Wordpress2PunBB Posting

Well, it isn't that easy I thought.
Your idea is nice but it doesn't working either.
I switched the function etc, but the punbb forum_db->escape() or query etc. will not be accepted by wordpress because wordpress uses wpdb->escape() or query etc.
Also switching from forum_db to wpdb doesn't work because wpdb needs more strings or something. I come now to the solution to do it all by myself with the wordpress queries etc.
It works well, but still is a very unelegant solution in my mind.
There are two things I am looking forward to fix. Help me if I am wrong with my solution.
1. Get the post into the index. If I saw it right then

        require FORUM_ROOT.'include/search_idx.php';

    update_search_index('post', $new_pid, $post_info['message'], $post_info['subject']);

is the thingy for indexing the post.
2. Increase the number of the poster in this way give me 1 extra post. (This at the moment not very important) Will work hopefully with an easy mysql update.

Of course I will the post the wordpress plugin here when it is done.

Re: Wordpress2PunBB Posting

Jones wrote:

I switched the function etc, but the punbb forum_db->escape() or query etc. will not be accepted by wordpress because wordpress uses wpdb->escape() or query etc.

As far as I understand you can use both wpdb and forum_db at the same time. I have no Wordpress environment and I have replaced your query

$wppost = $wpdb->get_row("SELECT post_date, post_title, post_content FROM ".$wpdb->posts." WHERE ID = ".$id." LIMIT 1");

to a simple assignment in my example. You still can return to your code and include modified files (my_essentials.php and my_functions.php) to avoid names conflict:

    define('FORUM_ROOT', './');
    require FORUM_ROOT.'include/my_essentials.php';

12 (edited by Jones 2010-04-21 11:55)

Re: Wordpress2PunBB Posting

Your true you can replace everything, but then it's in my mind an easier way to do without the include thing.
I will post the code here so that you can see how did I solved it.

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 = 'Greenday' 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(
    'Greenday',
    '".$wppost->post_title."',
    ".strtotime($wppost->post_date).",
    ".strtotime($wppost->post_date).",
    'Greenday',
    1)");
    $topic_id = $wpdb->insert_id;
    
    $wpdb->query("INSERT INTO ".PUNPREFIX."posts (poster, poster_id, message, posted, topic_id, poster_ip) VALUES(
    'Greenday',
    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 = 'Greenday' WHERE id = 1");
    $punbb_postnumber = $wpdb->get_row("SELECT num_posts, username FROM ".PUNPREFIX."users WHERE username = 'Greenday' LIMIT 1");
    $wpdb->query("UPDATE ".PUNPREFIX."users SET num_posts = ".$punbb_postnumber->num_posts."+1 WHERE username = 'Greenday'");
    
    /* 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;
    }
    }

How I said thats maybe not the best solution, but it's working very well for now.
Should be nearly the same what the function does.

Re: Wordpress2PunBB Posting

Of course, you're right and you are free to choose the solution. We can just give advice.

You've asked about adding posts to the search index. Seems like the PunBB database layer must be also included for the update_search_index() function to work.

Re: Wordpress2PunBB Posting

Hi guys, just a question; where should i put this code in?
Is it a WP extension so it is just to install or is more advanced?

I really want to get a working crossposting function, but i don't get it to work.

//david

15 (edited by aaronproctor 2013-05-03 23:14)

Re: Wordpress2PunBB Posting

Thank you, Jones, for starting this much needed integration between WordPress posts and punBB auto-posts.

I've made some adjustments to make the code easier to edit over here, since it's v.1.4 compatible:
http://punbb.informer.com/forums/post/149067/#p149067