1 (edited by tiendx2002 2009-01-03 16:23)

Topic: WordPress PunBB Complete integration

Hi all,
We have wanted to integrate punBB with WordPress and found these
http://punbb.informer.com/forums/viewtopic.php?id=16433
http://www.rkblog.rk.edu.pl/w/p/punbb-a … on-plugin/

Most of credit goes to the creator, we just modified it to suit our need (in fact it was not working for us, but we have changed some code so it works). This is for WP 2.7, punBB 1.3 latest

Our new code follow

<?php
/*
Plugin Name: punBB integrator
Plugin URI: http://www.rkblog.rk.edu.pl
Description: Allows Wordpress to manager punBB users - login/logout/register/password change etc.
Version: 0.0.07.2008.01
Author: Riklaunim
Author URI: http://www.rkblog.rk.edu.pl
*/
add_action('profile_update', 'punbb_profile_update');
add_action('wp_logout', 'punbb_wp_logout');
add_action('wp_authenticate', 'punbb_wp_authenticate', 1, 2);
add_action('user_register', 'punbb_user_register');
add_action('activate_jl-punbb/jl-punbb.php', 'punbb_sync_tables');

define('PUNPATH', './forum'); // path to punbb folder
define('PUNPREFIX', 'pun'); // punBB table prefix
define('LANGUAGE', 'English'); // punBB language name, English, etc.

function forum_hash($str, $salt)
{
    return sha1($salt.sha1($str));
}

function punbb_sync_tables()
    {
    global $wpdb;
    // copy users from WP to punBB that doesn't have account on punBB
    $q = $wpdb->get_results("SELECT * FROM ".$wpdb->users." WHERE user_login NOT IN (SELECT username FROM ".PUNPREFIX."users)");
    foreach($q as $u)
        {
        // give forum admin to the WP admin.
        IF($u->ID == 1)
            {
            $gid = 1;
            }
        else
            {
            $gid = 3;
            }
        $salt = md5(sha1(time().$u->user_login));
        $salt = substr($salt, 0,11);
        $wpdb->query('INSERT INTO '.PUNPREFIX.'users (username, group_id, password, email, email_setting, timezone, language, style, registered, registration_ip, last_visit, salt) VALUES(\''.$u->user_login.'\', '.$gid.', \'BRAK\', \''.$u->user_email.'\', 1, 1 , \''.LANGUAGE.'\', \'Oxygen\', '.time().', \''.strip_tags($_SERVER['REMOTE_ADDR']).'\', '.time().', \''.$salt.'\')');
        }
    // turn off emails for "dectivated" accounts on forum
    $wpdb->query('UPDATE '.PUNPREFIX.'users SET email_setting = 2 WHERE username NOT IN (SELECT user_login FROM '.$wpdb->users.') AND id > 1');
    }
    
function punbb_profile_update($id)
    {
    global $wpdb;
    $wpuser = $wpdb->get_row("SELECT user_login, user_email FROM ".$wpdb->users." WHERE ID = ".$id." LIMIT 1");
    $wpdb->query("UPDATE ".PUNPREFIX."users SET email='".$wpuser->user_email."' WHERE username = '".$wpuser->user_login."'");
    }
function punbb_wp_logout()
    {
    include PUNPATH.'/config.php';
    setcookie($cookie_name, NULL, time()-3600, '/', '', '0');
    }
function punbb_wp_authenticate($user_login, $user_pass)
    {
    global $wpdb;
    // wywołaj przy logowaniu jak masz dane
    IF($user_login and $user_pass and strlen($user_login) > 1 and strlen($user_pass) > 1)
        {
        $wpuser = $wpdb->get_row("SELECT id,user_pass FROM ".$wpdb->users." WHERE user_login = '".mysql_real_escape_string($user_login)."' LIMIT 1");
        if(wp_check_password($user_pass, $wpuser->user_pass, $wpuser->id))
            {
            $user = $wpdb->get_row("SELECT id, password, salt FROM ".PUNPREFIX."users WHERE username = '".mysql_real_escape_string($user_login)."' LIMIT 1");
            include PUNPATH.'/config.php';
            /*
            punBB uses sha1, wordpress md5. We have to cheat a bit. If the sha1 hash-password in punBB is "BRAK" (look at punbb_user_register)
            or it doesn't match sha1(password from good authentication) then we update it :)
            */
            IF($user->password == 'BRAK' OR sha1($user_pass) != $user->password)
                {
                $wpdb->query("UPDATE ".PUNPREFIX."users SET password='".sha1($user_pass)."' WHERE username = '".mysql_real_escape_string($user_login)."'");
                $user->password = sha1($user_pass);
                }
            $expire = time() + 31536000;
            
            //here we can get many informations
            $userInfoArray = $wpdb->get_row("SELECT id, group_id, password, salt FROM ".PUNPREFIX."users WHERE username='".mysql_real_escape_string($user_login)."'", "ARRAY_A");
            $salt = $userInfoArray['salt'];
            $form_password_hash = forum_hash($user_pass, $salt);
            $base64 = base64_encode($user->id.'|'.$user->password.'|'.$expire.'|'.sha1($user->salt.$user->password.forum_hash($expire, $user->salt)));
            if (version_compare(PHP_VERSION, '5.2.0', '>='))
                {
                setcookie($cookie_name, $base64, $expire, $cookie_path, $cookie_domain, $cookie_secure, true);
                }
            else
                {
                setcookie($cookie_name, $base64, $expire, $cookie_path.'; HttpOnly', $cookie_domain, $cookie_secure);
                }
            }
         }
    }
function punbb_user_register($id)
    {
    global $wpdb;
    $wpuser = $wpdb->get_row("SELECT * FROM ".$wpdb->users." WHERE ID = ".$id." LIMIT 1");
    $user = $wpdb->get_row("SELECT id FROM ".PUNPREFIX."users WHERE username = '".mysql_real_escape_string($wpuser->user_login)."' LIMIT 1");
    // user already exists in punbb
    IF($user->id)
        {
        $wpdb->query("UPDATE ".PUNPREFIX."users SET password='BRAK' WHERE username = '".mysql_real_escape_string($wpuser->user_login)."'");
        }
    // user does not exists
    else
        {
        $salt = md5(sha1(time()));
        $salt = substr($salt, 0,11);
        $wpdb->query('INSERT INTO '.PUNPREFIX.'users (username, group_id, password, email, email_setting, timezone, language, style, registered, registration_ip, last_visit, salt) VALUES(\''.$wpuser->user_login.'\', 3, \'BRAK\', \''.$wpuser->user_email.'\', 1, 1 , \''.LANGUAGE.'\', \'Oxygen\', '.time().', \''.strip_tags($_SERVER['REMOTE_ADDR']).'\', '.time().',\''.$salt.'\')');
        }
    }

?>

Cheers if it helps anyone.
Best Regards,
Tien (http://codeandmore.com).

Re: WordPress PunBB Complete integration

hi, thanks for the plugin,

but i am using fluxbb rev 718 and i want to integrate it with that, and i want to know what i need to change to do that as when i installed your version it didnt work, when i login it only logins to the wordpress not the forum.

you do know about fluxbb right, i hope you can tell me what to do to fix that.

MyFootballCafe.com  is Now Online!

Re: WordPress PunBB Complete integration

Hi SuperMAG,
We have never used fluxbb let us see what should be modified.
If any news I will post on this topic. smile
Best Regards,
Tien.

Re: WordPress PunBB Complete integration

ok thanks alot, by the way could you show me your site. just want to check the integration.

MyFootballCafe.com  is Now Online!

Re: WordPress PunBB Complete integration

Hi SuperMAG,
Here installed one integration
http://wpandpunbb.codeandmore.com/
(login with admin / madman)
We will disable this one soon. Just to show you.
Best Regards,
Tien (http://codeandmore.com).

Re: WordPress PunBB Complete integration

tiendx2002 wrote:

Hi SuperMAG,
Here installed one integration
http://wpandpunbb.codeandmore.com/
(login with admin / madman)
We will disable this one soon. Just to show you.
Best Regards,
Tien (http://codeandmore.com).


hi all,
big_smile
I would like to use the latest (possibly,or the safest) PunBB board with a WP 2.7.x

the Only function/sync I need is the cross posting , intending : read the posts's blog then reply post's on the PunBB.
I extensively searched on this forum without finding a definitive solution as mostly of you go for a deep syncing.

to have the possibility to put a  link below to each WP article,forwarding to the relevant  PunBB 3d would be nice,but it's not top priority.

Just  to post (twice) in both the platforms at once would be great (giving PunBB ability to 'understand' wp code)
Thanks for the reply,also a defenitive link could be ok.

cheers
lol

Re: WordPress PunBB Complete integration

thanks alot for the Example tiendx2002, really appreciated.

MyFootballCafe.com  is Now Online!

Re: WordPress PunBB Complete integration

sorry for upping neutral
but I'm really in need of that

Just  to post (twice) in both the platforms at once would be great (giving PunBB ability to 'understand' wp code)
Thanks for the reply,also a defenitive link could be ok.

wp2.7. and PunBB latest.

Re: WordPress PunBB Complete integration

Hi lorenzo,
Do you mean post on punbb and it will post on WordPress, it would be possible but we have to modify or create some punbb code to do so.
On the Wordpress it is possible as well, by writing a plugin, may be it will be easier for you to rent some one to do it for you.
Best Regards,
Tien (http://codeandmore.com).

Re: WordPress PunBB Complete integration

I have a userdatabase on Punbb already. Is it possible for existing users to post on my Wordpress blog if I install this plug-in?

Re: WordPress PunBB Complete integration

VincentBroccoli wrote:

I have a userdatabase on Punbb already. Is it possible for existing users to post on my Wordpress blog if I install this plug-in?

Hi VincentBroccoli,
This plugin is not yet covered that part, it just synced the WordPress user to punBB user database.
Best Regards,
Tien (http://codeandmore.com).

Re: WordPress PunBB Complete integration

hello again,

ok i had a fluxbb forum which i upgraded to punbb 1.3.2. on WP 2.7

now i installed the plugin.

and its not working.

it redirects the users to wp place but when i login to my wp account, it is not logged in punbb area.

MyFootballCafe.com  is Now Online!

Re: WordPress PunBB Complete integration

Hi SuperMAG,
Wonder if you use my source code or the original one?
Also have you activated the plugin (sorry this question might be silly for you, but most of the time it is silly issue).
Best Regards,
Tien (http://codeandmore.com).

14 (edited by SuperMAG 2009-01-05 11:56)

Re: WordPress PunBB Complete integration

ok here is what i did,

yes i used your code. Plugin and installed it in wordpress,
then i activited this extension in punbb,

<?xml version="1.0" encoding="utf-8"?>
<extension engine="1.0">
    <id>fluxbb_wordpress_integration</id>
    <title>FluxBB Wordpress Integration</title>
    <version>0.1</version>
    <description>Wordpress plguin required, based on code found at [url]http://www.rkblog.rk.edu.pl/w/p/punbb-and-wordpress-integration-plugin/[/url] - also the wordpress plugin found there will need to be installed. </description>
    <author>Rich Pedley</author>
    <minversion>1.3</minversion>
    <maxtestedon>1.3</maxtestedon>
    <hooks>
        <hook id="rg_start">
        <![CDATA[
            header('Location: [url=http://wrestlingfans.co.cc/wp-login.php?action=register);]http://wrestlingfans.co.cc/wp-login.php?action=register');[/url]
        ]]>
        </hook>
        <hook id="li_start">
        <![CDATA[
            header('Location: [url=http://wrestlingfans.co.cc/wp-login.php);]http://wrestlingfans.co.cc/wp-login.php');[/url]
        ]]>
        </hook>
        <hook id="po_end_validation">
        <![CDATA[
            header('Location: [url=http://wrestlingfans.co.cc/wp-admin/profile.php);]http://wrestlingfans.co.cc/wp-admin/profile.php');[/url]
        ]]>
        </hook>
    </hooks>
</extension>
MyFootballCafe.com  is Now Online!

Re: WordPress PunBB Complete integration

OH, it's great!  i am needing this plugin

Re: WordPress PunBB Complete integration

so any one find out why the integration is not working with my site.

MyFootballCafe.com  is Now Online!

17 (edited by GhostKilla 2009-01-15 16:50)

Re: WordPress PunBB Complete integration

Hi, i'm new on punBB, i've installed the latest version of punBB because my user want a board, i have a wordpress

so i've installed punBB with this plugin, but i have a little problem, for new user, it work very well, user is on wp and punBB table user, the cookies / login works

but for old member, the plugin not works, after update their profil, they don't are in the punBB table (me too the plugin don't works)

anyone say why i can update the table user of punBB with my old member ? or a script for copy user exist ?

thanks in advance and sorry for my bad english smile

18 (edited by SuperMAG 2009-01-15 20:41)

Re: WordPress PunBB Complete integration

yes thats my problem too, thats why i wasnt logged in to the account.... man

is there any way to convert users to the wp.

oh and by the way, does it work with old wp users.

i mean its like this:

Punbb  Old users: Not working
Punbb New Users Registered via WP: Working.
WP old Users: ???

MyFootballCafe.com  is Now Online!

Re: WordPress PunBB Complete integration

nope even if the new users are registered after the plugin installed, it still doesn't work.

MyFootballCafe.com  is Now Online!

Re: WordPress PunBB Complete integration

no for me it's my older member on Wp, i just install a fresh punBB today, and my member on wp can't login in punBB, the plugin don't copy my table user from wordpress to punbb user

i think for a coder it's dont really difficult to create this in php, because it's already in the plugin

but with newest member, it's ok, on wp and punBB

21

Re: WordPress PunBB Complete integration

I'm planing to use WordPress as well. I haven't touch it at all yet, so my suggestion can be completely wrong wink
In my opinion correct extension should generate proper WP cookie after punbb login (for users with WP access). Of course passwords should be the same.
Am I right, or completely wrong?

YonasH's repository + Extensions Directory = PunBB Extensions Online Library (in progress....)

Away. I will be back soon.

Re: WordPress PunBB Complete integration

hum, this plugin work very well, just create the possibility to import older member of wordpress on the user table of punBB (if you install punBB and you have many member registered in your wordpress)

but the cookie and login function are ok for new member, no problem for this

and password are the same

Re: WordPress PunBB Complete integration

and if i want recreate my user manually, i can paste "BRAK" in the password line, but what is "salt"  , i don't think why i can obtain this value ....

Re: WordPress PunBB Complete integration

it's ok, i've find a post for help me

-> http://punbb.informer.com/forums/topic/ … add-users/

25 (edited by SuperMAG 2009-01-21 17:17)

Re: WordPress PunBB Complete integration

ok i just used the original code of the author and it worked.

YAYSSSSSS

check this http://wrestlingfans.co.cc/forum/

MyFootballCafe.com  is Now Online!