I found a way to do this so this is a short set of instructions. This solution is far from perfect and neither are my instructions but I hope it'll be of use to someone who'd like to do the same, i.e. use their old phpBB userlist with Drupal and still keep phpBB as message board.

  • You'll need the following:
    Arne Kepp's module, found here: http://drupal.org/node/32818
    An existing phpBB forum
    A Drupal installation
  • BEFORE YOU START: Make backups of your phpBB and your Drupal databases!
  • Start by reading the README that comes with the module above, do so very carefully.
  • I'd also like to advise people against trying this unless they are able programmers. It gets technical!
  • The module sorts everything apart from importing old users from phpBB to Drupal. This was I had to figure it out for myself. This presents a problem as both Drupal and phpBB makes the first user admin however they have different IDs (IDs or UIDs are used to indentify records in a db table), as illustrated below:
    Drupal --------- phpBB
                     -1 Anononymous
    0 Anonymous
    1 Admin
                     2 Admin
    
  • In order to import your phpBB users to Drupal, run the following SQL query (in phpMyAdmin for example), this one is from Feodor's migration script:
    INSERT INTO <your_drupal_database_name>.users (uid,name,pass,mail,mode,sort,threshold,theme,signature,created,changed,status,timezone,language,picture,init,data)
      SELECT  user_id,username,user_password,user_email,0,0,0,'',user_sig,user_regdate,user_lastvisit,1,0,'',user_avatar,user_email,'a:1:{s:5:"roles";a:1:{i:0;s:1:"2";}}'
      FROM <your_phpbb_database_name>.phpbb_users
      WHERE user_id>=@first_phpbb_user_id;

    You have to replace @first_phpbb_user_id with the ID of the first phpBB user, usually 2

  • Then add all users you just added to the users_roles junction table, this matches a user and his/her role so that a user can have more than one role:
    INSERT INTO `users_roles` (uid)
      SELECT  uid
      FROM jakobp_drupal.users
      WHERE uid>=3;
  • Now run this query, this will set the role of every registered user as "authenticated":
    UPDATE `users_rules` SET rid =2 WHERE uid > 0;
    
  • (I am sure you can combine the last two queries into one but I haven't had time to figure that out yet. :))
  • You might have noticed that the phpBB admin account is unchanged. You will from now on use your Drupal admin account for both your forums and your Drupal installation. I think it would be better to find a way to merge the accounts or allow both to be used but this is a limitation in the module.
  • We're almost done. You need to change the auto_increment value of the two user tables. The auto_increment value affects the value of the id field of new records. We will want these values to be identical or the two user tables will not be synchronized. The new auto_increment value should be high, you can check the id of the last user to see. I recommend adding 1000 to it. In the unlikelihood that you just deleted a few hundred users from your table, the actual increment value will be higher than the last value you see.

    To do so, execute these SQL queries where X is the new increment value:

    ALTER TABLE phpbb_users AUTO_INCREMENT = X;
    ALTER TABLE users AUTO_INCREMENT = X;
  • We also need to update the last UID value, Drupal uses this to keep track of the last UID added to the users table, same applies here, replace X with the new increment value:
    UPDATE `sequences` SET `id` = 'X' WHERE `name` = 'users_uid' LIMIT 1;
    

Now that should sort it. If you have questions feel free to post.

Comments

Drahcir’s picture

Integration of third party scripts is an important issue:

Developers of third patry scripts usually give prime attention to making their product as excellent as possible, so why do we try to make a forum (for example) when there are already many proven systems already available?

Surely the tacticle move is to make them "integrateable" rather than re-invent the wheel again and again by making Drupal versions.

To me, some key issues here are to make it clear how to do 2 main things:

1- How to include a web application into a drupal site.
2- How to integrate drupal login permissions for that script.

Is there a procedure for this?

Personally I would like to use http://getvanilla.com/ vanilla forums.

Thanks, for your details above.

arkepp’s picture

You have turned the issue upsidedown, like most non-developers do.

It is not the Drupal developers that must make it easy to integrate third-party programs. They have already done a very good job at this.

The majority of the work is required by the people who want their programs to be included in other frameworks. For example, Gallery ( http://gallery.sf.net ) does an excellent job. It provides functions and hooks that let other PHP applications easily include its content and functionality on any kind of webpage. Many content management systems (CMSs, like Drupal) and forums therefore support the integration of Gallery.

phpBB, on the other hand, makes it nearly impossible to use any of the code outside of the original framework. If you want to see topics, you must call viewtopics.php. And viewtopics.php will call a template and return a load of things that cannot be used within an existing webpage. There are mods for phpBB that make this easier, but they are incomplete and not officially supported.

And for exactly the same reason, phpBB can be improved upon. Hopefully 2.2.x will be better, but a lot of the basic design was repeated last time I checked.

solipsist’s picture

I'd be one of the first to start a real discussion about this over at phpBB.com. Lots of people wonder how they can use phpBB with a CMS and I think both phpBB and Drupal would gain from phpBB being easier to develop for.

Sadly having seen the phpBB project from the inside I know they have strict hierarchies, at least that's the way it was when I was involved, and I think they could do a better job taking care of ideas that are coming from their community.

What I am very impressed with is how the module Arne here made requires no changes to phpBB. It doesn't work perfectly for me yet but I think I'll sort it in a day or two. I'm using phpBB 2.0.19, module is said to work with 2.0.18, which may explain the problems I have with admin panel re-authentication (which I disabled and replaced with .htaccess protection), cookies and sessions that won't register. I remain positive we'll find a solution soon.

--
Jakob Persson - blog
Leancept – Digital effect and innovation agency

taslett’s picture

Hi solipsist,
Well done.
I am looking at doing this sometime in the near future and have a couple of questions.
Have you had any problems with it so far?
Do you have an example site we could have a look at?
Are new user accounts now stored only in Drupal or both Drupal and PhpBB?

www.csscreator.com

solipsist’s picture

1. Yes, auto-login for phpBB doesn't work flawlessly yet. I might just disable it.

2. Mine, when it's done but it will be a while. I have other priorities right now.

3. When users try and register for phpBB they are automatically redirected to Drupal. Accounts created in Drupal are mirrored in the phpBB users/groups table so it's synched, yes.

--
Jakob Persson - blog
Leancept – Digital effect and innovation agency

arkepp’s picture

http://linux1.no
and
http://mac1.no
are examples. In norwegian, but you can probably manage.

The only issue we have right now is when users manage to delete their phpBB cookies, but keep the Drupal one. phpBB then sends them to Drupal to log in, which redirects them back to the referring page, since everything appears to be ok.

This obviously happens extremely rarely (roughly twice a week with 5000 users), and by now the forum is stuffed with threads about how you need to log out and back in to fix it.

I think a fix through code would require a special page, i.e. that the user gets sent from login to an intermediary before being bounced to phpBB. This intermediary could check for both sets of cookies, since the phpbb-module functions are never called on a "normal bounce"... dunno if that made sense to anyone. Feel free to code it up if it did, I won't be able to do it until end of March unfortunately, and I'm still not sure I like it.

Another option would be for Drupal to actually re-login, even though the sessions already exists.

solipsist’s picture

Cool. I actually disabled the automated login for phpBB as it just didn't seem to work, you got logged into Drupal but not into phpBB, people at my site will have to log in manually to phpBB.

--
Jakob Persson - blog
Leancept – Digital effect and innovation agency

smilodon’s picture

You guys got it to work... i admire this...
Could you help me ?
http://drupal.org/node/14563#comment-110005
I posted it to another thread already.
PS:
theres a fix to the install.txt below this comment link
and a "bug report" as in reply...

clauz’s picture

http://drupal.org/node/64072

Clauz
---------------------------------
http://www.clauz.com.ar
...I am going through A Momentary Lapse of Reason...

b.jon’s picture

How did u get phbb do be dysplayed in drupal. I got the autologin and shared users between drupal and phbb but currently the phpbb link opens as if i had just the forum, no more drupal links, content,theme etc.
On closer inspection it isn't actualy integrated into drupal. Wish i could display phbb and still keep the top, lef and right sidebars.

solipsist’s picture

You have to make a phpBB template that looks just like your Drupal theme.

--
Jakob Persson
Drupal developer, web designer and usability consultant
http://www.jakob-persson.com

--
Jakob Persson - blog
Leancept – Digital effect and innovation agency

travist’s picture

No not really....

I actually was able to get phpBB to show through the Drupal page. I did this using the Services Module and XML-RPC message handling between Drupal and the phpBB installation. Basically how this works is instead of phpBB drawing its template on the screen, I instead send that page to drupal using XML-RPC...then I receive that message, add that content to theme('page', $content) and then send it back to phpBB. This way I can have as many phpBB templates as I want without modifing all of them... I just adding about 5 lines of code to the phpBB's template.php file and was done with the phpBB mod. It works great!

vb’s picture

travist

I just adding about 5 lines of code

Please, write this 5 lines and arguments when calling XML-RPC.
Please explain what you return to phpbb

travist’s picture

First, I had to do some more than just 5 lines of code in phpBB to get it to work the way I wanted...

Here is what I did.

  • Download XML-RPC for PHP from http://phpxmlrpc.sourceforge.net/
  • Place this library in phpBB's path includes/lib
  • Open up phpBB's phpBB's template.php file....
  • Place the following function in the template.php file.
    <?php
       /**  
        * Drupal Template hack by Travis Tidwell : www.travistidwell.com
    	 *    Tap into the template system to allow for Drupal to load its template first, and then place the forum in the content of the theme.
    	 *    This is assuming that you have your phpBB instalation within a directory that is one level higher than the Drupal Root.  For example,
    	 *    drupal_root/phpBB/index.php is valid, while drupal_root/forum/phpBB/index.php is not.
    	 */
    
       function showDrupal($content) {
    		require_once('lib/xmlrpc.inc');
    		$client = new xmlrpc_client('http://'.$this->sitename.'/services/xmlrpc');
    		$client->return_type = 'phpvals';
    		$content_var = new xmlrpcval($content, "string");
    		$sessid = new xmlrpcval($this->sid, "string");
    	
    		$message = new xmlrpcmsg("phpbb.getpage", array($sessid, $content_var));
    		$resp = $client->send($message);
    		if ($resp->faultCode())
      	   	echo 'KO. Error: '.$resp->faultString();
    		else
    			echo $resp->value();
       }
    ?>
    
  • Now change the pparse routine to the following...
    <?php
    	/**
    	 * Load the file for the handle, compile the file,
    	 * and run the compiled code. This will print out
    	 * the results of executing the template.
    	 */
    	function pparse($handle)
    	{
    		if (!$this->loadfile($handle))
    		{
    			die("Template->pparse(): Couldn't load template file for handle $handle");
    		}
    
          $content = "";
    
    		// actually compile the template now.
    		if (!isset($this->compiled_code[$handle]) || empty($this->compiled_code[$handle]))
    		{
    			// Actually compile the code now.
    			if(defined('IN_ADMIN') && IN_ADMIN) {
    				$this->compiled_code[$handle] = $this->compile($this->uncompiled_code[$handle]);
    			}
    			else {
    				$this->compiled_code[$handle] = $this->compile($this->uncompiled_code[$handle], true, 'content');
    			}
    		}
    
    		// Run the compiled code.
    		eval($this->compiled_code[$handle]);
    		
    		if(defined('IN_ADMIN') && IN_ADMIN) {
    			return true;
    		}
    		else {
    			if(strpos($handle, 'header') !== FALSE) {
    				$_SESSION['page_header'] = $content;
    			}
    			else if(strpos($handle, 'body') !== FALSE) {
    				$_SESSION['page_body'] = $content;
    			}
    			else if(strpos($handle, 'footer') !== FALSE) {
    				$content = $_SESSION['page_header'] . $_SESSION['page_body'] . $content;
    				$this->showDrupal($content);		
    			}
    		}
    		
    		return true;
    	}
    ?>
    
  • Now download the Services Module and enable it...
  • Now you just need to edit the phpbb.module file and add the following lines of code...
    <?php
    /**
     * phpBB Drupal Hack by Travis Tidwell, www.travistidwell.com
     *
     * phpbb_get_page :  This function is called with the XML-RPC from the phpBB template engine.  It passes the 
     * content of the forum page to this routine, and then waits to get a response to print to the screen.  This function
     * takes that content, and then merges the two templates together before it sends it back to the phpBB template engine.
     */
    
    function phpbb_get_page($content) {
      $body_start = '<table width="100%" cellspacing="0" cellpadding="10" border="0" align="center"><tr><td class="bodyline" '.$background_color.'>';
      $body_end = '</td></tr></table>';
      $tolower = strtolower($content);
      $template = variable_get('phpbb_template', 'subSilver');
      $phpBBPath = variable_get('phpbb_dir', 'phpBB2/');
      $content = str_replace('templates/', $phpBBPath . 'templates/', $content);
       
      drupal_add_css("{$phpBBPath}templates/{$template}/{$template}.css", 'theme');
      drupal_set_title(variable_get('phpbb_forum_title', 'Forum'));
       
    /*
     * Doesn't quite work yet...
     *
     * drupal_set_html_head(_extract_tag_info($content, $tolower, '<style', '</style>'));     // Copy all links to the drupal header.
     * drupal_set_html_head(_extract_tag_info($content, $tolower, '<link', '>'));             // Copy all links to the drupal header.
     * drupal_set_html_head(_extract_tag_info($content, $tolower, '<script', '</script>'));   // Copy all scripts to the drupal header.
     */
      $startpos = strpos($tolower, '<body');
      $startpos = strpos($tolower, '>', $startpos) + 1;
      $endpos = strpos($tolower, '</body>');
      return theme('page', substr($content, $startpos, ($endpos - $startpos)));
    }
    
    /*
    * Implementation of hook_service()
    * Required by all server modules
    * Returns array defining all the methods available in the service
    */
    function phpbb_service() {
      return array(
        array(
          '#method' => 'phpbb.getpage',
          '#callback' => 'phpbb_get_page',
          '#args' => array(
            array(
              '#name' => 'content',
              '#type' => 'string',
              '#optional' => false,
              '#description' => 'A string of the content of the bulletin board.'       
            ),
          ),
    
          '#return' => 'string',
          '#help' => 'Returns a drupal page with the content provided.'
        )
      );
    }
    ?>
    

And that's how I did it!!!

Enjoy,

Travis.

vb’s picture

Thank you for code.
I will try to implement.

Vadim

staylor’s picture

I wonder if you tried these changed and managed to implement them with success?

Ive just installed the arkepp phpbb module and can link from drupal to phpbb3 but i want to embed the forum into the drupal page.
Is there an easier way?

KrisBulman’s picture

i've integrated phpbb3 and drupal5 user accounts etc.. via arkepp's module.. and i'd now like to encapsule phpbb in drupal but not just by theming..

some points were layed out on ways to do this, here: http://groups.drupal.org/node/7302#comment-23735

Travis, will what you have documented above work for phpbb3?

flosi’s picture

...if I have Drupal 5.x and phpbb 2.0.19 (and if everything should work properly) or do I have to upgrade phpBB or downgrade Drupal or what?

Thanks!
flo

solipsist’s picture

I think the phpbb.module has been ported to Drupal 5 by now, so get the most recent version of both.

--
Jakob Persson
Drupal developer, web designer and usability consultant
http://www.jakob-persson.com

--
Jakob Persson - blog
Leancept – Digital effect and innovation agency

solipsist’s picture

These instructions are not for phpBB3. I may write a similar tutorial for phpBB3 eventually.

--
Jakob Persson
Drupal developer, web designer and usability consultant
http://www.jakob-persson.com

--
Jakob Persson - blog
Leancept – Digital effect and innovation agency

kopeah’s picture

Actually it worked for me with minor changes on the first SQL query. I did data conversion from phpBB 2.x to 3.x then followed these instructions. One problem that I'm having right now is with users that has admin rights to the forum. For some reason, even after they update their password .. they couldn't login to ACP.

solipsist’s picture

I strongly recommend you to read the instructions arkepp has made available. These were not meant for phpBB3. The problem you have could very well be related to that.

--
Jakob Persson
Webbredaktoren - www.webbredaktoren.se

--
Jakob Persson - blog
Leancept – Digital effect and innovation agency

KrisBulman’s picture

if you were ever to make it.. especially the latter half.. using the services module and XML-RPC message handling between Drupal5 and phpBB3

AlexJTanner’s picture

please write one

Dorian_Gray’s picture

Hi,

Solipsist, thank you for sharing your work ! It is very close from what I an trying to do. Maybe you can help me, if you wish, because there is very little work to do.

I will soon start a web site with Drupal & Phpbb 3 forum. I would like users to register only once (in phpbb) and let them use their login and password with both phpbb and drupal.

So I need to write two function for user management. These functions will be called from phpbb each time an user registers. The user will be added as "normal user" into drupal's database.

function User_add_drupal($User_login, $User_password, User_mail); // User_password is the non encoded password
function User_update_drupal( $User_login, $New_user_mail); // Will change the mail of user_login

To make It very simple :

- Phpbb and Drupal will open at the same time. So, there will be no need to check if the user is already in Drupal's database.
- User will not be allowed to change their login.
- Account Removal will be performed by an admin, on request.

I think I just have to modify some of the code you provided above. I tried, but I failed. And there are many things I don't understand.
Please, could you help me ?

_________________________________________________
Edit : Here is what I don't understand :

- This bit of code :
'a:1:{s:5:"roles";a:1:{i:0;s:1:"2";}}

- Why is "init" from drupal_users filled with "user_email" from phpbb_users ?

- Do I need to run this ? And why ?

ALTER TABLE phpbb_users AUTO_INCREMENT = X;
ALTER TABLE users AUTO_INCREMENT = X;
UPDATE `sequences` SET `id` = 'X' WHERE `name` = 'users_uid' LIMIT 1;
solipsist’s picture

Get the latest version of the phpBB module and read arkepp's instructions that come with it carefully - they work with phpBB3. My instructions only apply to phpBB2 and your questions above should be explained in my post if I recall correctly - it has to do with making sure new user ids do not conflict.

--
Jakob Persson
Webbredaktoren - www.webbredaktoren.se

--
Jakob Persson - blog
Leancept – Digital effect and innovation agency

coolatt’s picture

I have an existing phpBB3 forum and planning to install drupal 6.
Can someone assure me that phpBB3 will work with drupal6.

My existing phpBB3 forum authenticate using an LDAP server. i also want drupal to authenticate with ldap
i want to configure drupal & phpBB so that once users have logged in drupal they automatically access the forum without any further login.
i want to know if this is possible,,, plz guide me,,, thanks.