1

(8 replies, posted in PunBB 1.2 show off)

I love the site.  Great idea, very broad and inclusive.  It seems like with enough users it could easily become a one-stop shop for expatriate needs.  I love the idea of a site like this, because moving to another country is something that I've considered doing in the past and possibly in the future, and would be in need of a place where I could connect with people living in different areas to point me in the right directions.

Integration looks fantastic!  I'm very impressed with the way things are laid out.  Your layout and functional breakup (one forum per region) is intuitive, and the subforums by country are perfect.  I don't think I agree with breaking countries down by city, though.  I understand that different cities in a country are different but it may be too specific.  If a particular country's forum becomes well-used and the users request a breakdown by city, then you might add that, but until the breakdown is required I would think it best just to limit to countries.  I really like your idea though and it seems like some of the forums are picking up a little traffic.  With enough promotion you really could have something.

Yeah, I looked a lot here, on wordpress and their theme site, and on Google and Yahoo! and couldn't find anything.  So I gave up and used this theme from Quaker.  I hunted down the Wordpress theme from the original creator and then did a custom version for my Singapore photo gallery and a separate custom one for any pages that I wanted to include, separately, which I used for my LastRSS feed aggregation on my front page.  I'm playing with ideas to modify it so that it's a liquid layout instead of fixed-width.

I can confirm that the code I posted in message #71 works with both WordPress 2.5 and 2.5.1 without modifications.

Good luck with 1.3!

I haven't tested that, yet, because the stable 1.3 hasn't been released.

So, I'm looking to integrate wordpress and punbb and I was wondering if anyone has seen an Oxygen them (or similar) for WordPress?  I've been looking all over and can't seem to find one.

Got it working!  cool

I redid my paths after I got it so that they were relative instead of hard-coded, which should make it work better (or at least with less modification) for other people.  Working code is at the end of this post.  I would like to massage it a little when I have some time to remove the pun includes so that it lives up to the previous ease of use (and will also make future changes easier). 

I also fixed one other issue that always bugged me.  When you click logout of the forums you still have to click logout on the blog.  I like one-click functionality.  To do this, you edit your punbb login.php slightly differently than explained before.  Don't put the line in as previous instructions.  Around line 39, find the line:

$action = isset($_GET['action']) ? $_GET['action'] : null;

After it, put:

if ($action == 'out')
    header('Location: http://www.hugthecenterline.com/blog/wp-login.php?action=logout');
else
    header('Location: http://www.hugthecenterline.com/blog/wp-login.php');

That's it!  One-click shopping.

Thanks for all your help Riklaunim, and for making this excellent plugin in the first place!  big_smile

Edit:  I guess the version number should be changed.  I don't know your numbering scheme so let me know what you want it changed to.

Here's my jl-punbb.php file to replace the stock one in the plugins folder after you do the install:

<?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.13.666
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

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 = 4;
            }
        $wpdb->query('INSERT INTO '.PUNPREFIX.'users (username, group_id, password, email, email_setting, save_pass, timezone, language, style, registered, registration_ip, last_visit) VALUES(\''.$u->user_login.'\', '.$gid.', \'BRAK\', \''.$u->user_email.'\', 1, 1, 1 , \'English\', \'Oxygen\', '.time().', \''.strip_tags($_SERVER['REMOTE_ADDR']).'\', '.time().')');
        }
    // 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");
//        AUTHENTICATION FOR WORDPRESS HAS CHANGED IN VERSION 2.5
//        if(md5($user_pass) == $wpuser->user_pass)
        if(wp_check_password($user_pass, $wpuser->user_pass, $wpuser->id))
            {
            $user = $wpdb->get_row("SELECT id, password 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 :)
            */

            //DEFINITIONS REQUIRED TO REQUIRE PUNS GLOBALS
            define('PUN_TURN_OFF_MAINT', 1);
            define('PUN_QUIET_VISIT', 1);
            define('PUN_ROOT', '../forum/');
            global $db, $pun_config, $pun_user, $lang_common;
            require PUN_ROOT.'include/common.php';

            //PUNS HASH METHOD HAS CHANGED... CALL THEIR FUNCTION
            if($user->password == 'BRAK' OR pun_hash($user_pass) != $user->password)
                {
                //COMMENTED THIS OUT BECAUSE I DON'T WANT IT TO RUN.  WILL NOT UPDATE PUN'S DB CORRECTLY
//                $wpdb->query("UPDATE ".PUNPREFIX."users SET password='".sha1($user_pass)."' WHERE username = '".mysql_real_escape_string($user_login)."'");
                }

            //SETTINGS REQUIRED TO SET PUNS LOGIN COOKIE
            $user_id = $user->id;
            $form_password_hash = pun_hash($user_pass);    // This could result in either an SHA-1 or an MD5 hash (depends on $sha1_available)    
            $expire = ($save_pass == '1') ? time() + 31536000 : 0;
            $cookie_name="punbb_cookie";
            $cookie_path="/";
            $cookie_secure = 0;
            $cookie_seed = "957942b8";    
            //SET THE COOKIE.  THIS IS TAKEN FROM PUN'S include/functions.php FILE.
            setcookie($cookie_name, serialize(array($user_id, md5($cookie_seed.$form_password_hash))), $expire, $cookie_path, $cookie_domain, $cookie_secure, true);

            }
         }
    }
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
        {
        $wpdb->query('INSERT INTO '.PUNPREFIX.'users (username, group_id, password, email, email_setting, save_pass, timezone, language, style, registered, registration_ip, last_visit) VALUES(\''.$wpuser->user_login.'\', 4, \'BRAK\', \''.$wpuser->user_email.'\', 1, 1, 1 , \'Polish\', \'Oxygen\', '.time().', \''.strip_tags($_SERVER['REMOTE_ADDR']).'\', '.time().')');
        }
    }

?>

All mine are hard-coded.  I'm going to poke around in the functions and see if I can see how the cookie is set for login.

My setcookie is taken form pun_setcookie function to avoid including punBB and playing with $variables globalisation big_smile

Sounds like a good idea.  My understanding from the documentation was that it would be easy to just include the file.  Oh well.

So, I got the code to run through all the spots that it should, but the cookie doesn't seem to be setting in such a way that I'm being logged in.  What file is the pun_setcookie function in? 

I have to go to class right now but I'll be back in about four hours.  I'm not sure what your schedule is like but I'll leave a note on the forum when I'm here again.  Thanks again for all your help!

I edited at the same time as you posted, not sure if you caught my edit.  It's telling me there is no valid language pack.  I only have English installed (I guess... I didn't really "install" it).

Where do I global it?  In the include/functions.php or before the require line in jl-punbb?

I added this:

global $db;

right before:

require PUN_ROOT.'include/common.php';

and got this:

There is no valid language pack '' installed. Please reinstall a language of that name.

???

So, I've been hacking on jl-punbb and poking around in the punbb and wordpress documentation and functions and here's what I've found so far:

First thing I did was replace all IF statements with if (changed case).  Not sure if it's necessary, but it made me more comfortable.

On line 58 the code was:

$wpuser = $wpdb->get_row("SELECT user_pass FROM ".$wpdb->users." WHERE user_login = '".mysql_real_escape_string($user_login)."' LIMIT 1");

I changed it to:

$wpuser = $wpdb->get_row("SELECT id,user_pass FROM ".$wpdb->users." WHERE user_login = '".mysql_real_escape_string($user_login)."' LIMIT 1");

Wordpress changed the way they do authentication.  On line 59 or so there is the line:

if(md5($user_pass) == $wpuser->user_pass)

I changed it to:

if(wp_check_password($user_pass, $wpuser->user_pass, $wpuser->id))

and that seems to work the way I want it to, using the new WordPress login credentials.

On line 68 there is the line:

IF($user->password == 'BRAK' OR sha1($user_pass) != $user->password)

PunBB also changed the way they do authentication so I changed it to:

if($user->password == 'BRAK' OR pun_hash($user_pass) != $user->password)

It told me that pun_hash function was undefined so I added:

define('PUN_TURN_OFF_MAINT', 1);
define('PUN_QUIET_VISIT', 1);
define('PUN_ROOT', '/path/forum/');
require PUN_ROOT.'include/common.php';

right before that line.  Then I get this error:

Fatal error: Call to a member function query() on a non-object in /path/forum/include/functions.php on line 125

So, I pop open /include/functions.php and here is line 125:

    // Fetch guest user
    $result = $db->query('SELECT u.*, g.*, o.logged FROM '.$db->prefix.'users AS u INNER JOIN '.$db->prefix.'groups AS g ON u.group_id=g.g_id LEFT JOIN '.$db->prefix.'online AS o ON o.ident=\''.$remote_addr.'\' WHERE u.id=1') or error('Unable to fetch guest information', __FILE__, __LINE__, $db->error());

And I'm stuck.  I'm not sure why the $db isn't an object. 

After that my plan was to change line 71:

setcookie($cookie_name, serialize(array($user->id, md5($cookie_seed.sha1($user_pass)))),  time() + 31536000, $cookie_path.'; HttpOnly', $cookie_domain, $cookie_secure);

to:

$user_id = $user->id;
$form_password_hash = pun_hash($form_password);    // This could result in either an SHA-1 or an MD5 hash (depends on $sha1_available)    
$expire = ($save_pass == '1') ? time() + 31536000 : 0;
pun_setcookie($user_id, $form_password_hash, $expire);

So, hopefully this will shortcut some of the troubleshooting for you.  I'm anxious to get this plugin working again.  Thanks for you help.  smile

Edited because I remembered some other changes I made.  I think that's all of them.  smile

I updated to the new WordPress 2.5 and PunBB 1.2.17 this past weekend and I have been trying unsuccessfully to recreate the single login voodoo that I had before (WordPress 2.3 and PunBB 1.2.15).

Everything in the PunBB side points to the WordPress pages the same way but when I log into WordPress then try to visit PunBB it says that I'm not logged in.  I am familiar with PHP but between these two systems there are too many variables to keep track of. 

Does this plugin work with WordPress 2.5 and PunBB 1.2.17 (I know it was developed with previous versions) and if so can someone talk me through getting it working again?  If not, is there anyone that can help me hack it so that it does?  Thanks.

So, I'm messing around with my header.  I have a Wordpress blog in /blog (folder in my site) and the forum is installed in /forum.  I messed around with my blog header and got it the way I like it.  Now I'm messing around with my pun header to make it use my blog header. 

I used a pun_include in my main.tpl called masthead.php and in the user/include/masthead.php file I'm trying to use the template tags <pun_title> and <pun_desc>.  Any way to do this?

Specifically, the blog header calls the functions get_option() and blog_info() so in my masthead.php I defined the functions and am trying to return the path to the blog for the first and echo the <pun_title> and <pun_desc> in the second to create the headline for my header.  It gives me this error:

Parse error: syntax error, unexpected '<' in /forum/include/user/masthead.php on line 3

That's obviously where the <pun_title> is.  Do I need to declare something in masthead.php to use these template tags?  Or, is there a different variable I should be using (that contains the same info)?  I want the info to be generated based on whatever values I punch in the admin panel and I expect to be changing the values occasionally so I do not want them to be hard-coded into the main.tpl or masthead.php files.

Thanks for any help.

Edit: So, I've been poking around in the source and the best I can tell, I should be able to use template tags.  The part that does the parsing, I think, is in /header.php:

// START SUBST - <pun_include "*">
while (preg_match('#<pun_include "([^/\\\\]*?)\.(php[45]?|inc|html?|txt)">#', $tpl_main, $cur_include))
{
    if (!file_exists(PUN_ROOT.'include/user/'.$cur_include[1].'.'.$cur_include[2]))
        error('Unable to process user include '.htmlspecialchars($cur_include[0]).' from template main.tpl. There is no such file in folder /include/user/');

    ob_start();
    include PUN_ROOT.'include/user/'.$cur_include[1].'.'.$cur_include[2];
    $tpl_temp = ob_get_contents();
    $tpl_main = str_replace($cur_include[0], $tpl_temp, $tpl_main);
    ob_end_clean();
}
// END SUBST - <pun_include "*">

My understanding of this is that the code runs through main.tpl and looks for any instances of <pun_include *> where * is a valid value.  It puts any instances it finds into the $cur_include array.  Let's skip over the error because it is parsing my file.  It starts an ouput buffer and puts my file to the output buffer, stores my included file in it, then stores the output buffer in $tpl_temp.  From there, it runs through $tpl_main and replaces any instances of $cur_include[0] with $tpl_temp, then flushes the output.  $cur_include[0] is going to be the pun_include, though.  So, it's going through $tpl_main and looking for anywhere there is a pun_include masthead.php (in my case) and replaces it with the results. 

So, I'm wrong.  It doesn't replace my template tags here.  Ignore this edit (though I'm leaving it as a reference for myself later).

2nd Edit: Right here, further down the header.php page, is where it's parsed.

// START SUBST - <pun_title>
$tpl_main = str_replace('<pun_title>', '<h1><span>'.pun_htmlspecialchars($pun_config['o_board_title']).'</span></h1>', $tpl_main);
// END SUBST - <pun_title>


// START SUBST - <pun_desc>
$tpl_main = str_replace('<pun_desc>', '<p><span>'.$pun_config['o_board_desc'].'</span></p>', $tpl_main);
// END SUBST - <pun_desc>

Since my page has been included in $tpl_main before this anywhere in my masthead.php that it says <pun_title> or <pun_desc> should be parsed into the appropriate values.

3rd Edit: After verifying that it is supposed to parse them I thought about the problem a little more.  It wasn't recognizing my <pun_title>.  The code looked like this:

function bloginfo($option) {
    if ($option == "name") echo <pun_title>;
    elseif ($option == "description") echo <pun_desc>;
}

For anyone that stumbles on this down the road through a search, I solved the problem by putting <pun_title> and <pun_desc> in single quotes, like so:

function bloginfo($option) {
    if ($option == "name") echo '<pun_title>';
    elseif ($option == "description") echo '<pun_desc>';
}

I hate being foiled by quotes.

Thanks for the quick reply!  I really didn't think I'd have anything to work with until tomorrow!

Since I had literally *just* done the install and hadn't customized anything (except for your plug-in) I just deleted out my forum and reinstalled using the same database.  I edited the language to English and re-activated your plug-in in Wordpress and it worked like a charm!

Thanks again.

Neat plugin but I'm having trouble making it work.  I followed the steps and everything seemed to go well.  The only things that I have different are that users cannot register themselves in my wordpress plugin.  Also, my wordpress and my punbb have different databases on my server.  Should they use the same database and use the table-prefix of 'pun_' for this plugin to work correctly?

When I go to the admin section of wordpress and add a user I get the following error message:

WordPress database error: [Table 'wordpressMain.pun_users' doesn't exist]
SELECT id FROM pun_users WHERE username = '' LIMIT 1

WordPress database error: [Table 'wordpressMain.pun_users' doesn't exist]
INSERT INTO pun_users (username, group_id, password, email, email_setting, save_pass, timezone, language, style, registered, registration_ip, last_visit) VALUES('test4', 4, 'BRAK', 'test4@test.com', 1, 1, 1 , 'Polish', 'Oxygen', 1187640923, '192.168.1.1', 1187640923)

Warning: Cannot modify header information - headers already sent by (output started at /var/www/mep/httpdocs/blog/wp-includes/wp-db.php:133) in /var/www/mep/httpdocs/blog/wp-includes/classes.php on line 734
9 test4 test4 test4 test4@test.com

Also, looking over this post I see that the plugin is trying to set the language to Polish on the insert statement.  For English, do I just change that in the php to English?  Thanks.