Nucleus Support Forum Index

Find on the forum:
any terms  all terms  Advanced Search

RSS 2.0
Browse posts: Unanswered | Mark all read

« »
Loading Nucleus FAQ ticker...
Post new topic This topic is locked: you cannot edit posts or make replies.
Author Message
Trent
Nucleus Guru
Nucleus Guru


Joined: 04 Oct 2002
Posts: 1555
Location: Alberta, Canada

Post Posted: Sun Jan 23, 2005 3:00 am   Post subject: NP_phpBB - **Working Code**
Reply with quote

This plugin was developed by Andrew Black to have users of phpBB forums be authenticated in Nucleus using the phpBB cookie. If the user doesn't exist in Nucleus, it will be created. This allows all people with existing phpBB forums to have users created and authenticated in Nucleus and allows all registrations to be done through phpBB versus Nucleus (admin approval on registration from phpBB) if you use the NP_AutoJoinBlog plugin available at http://forum.nucleuscms.org/viewtopic.php?t=5715

INSTRUCTIONS:

Ok guys, let me explain how I got this one going!

I used the code (that I will paste in a minute) and installed the plugin without any errors after uninstalling previous versions.

Then I edited the plugin options to use the server location of my phpBB files. In my case it was in a directory called 'forum' versus what most people use with phpbb2 or whatever. I had to use the server location like /home/www/html/forum/ to work in the plugin options because using a URL or just ../forum/ didn't work for me.

***Key notes to remember***

You must have the phpbb database files in the same database as Nucleus! I don't know if it is important, but I didn't change the database extensions for either Nucleus or for phpBB, so I am not sure if this works right if you did change them.

Now, another thing I did was make sure that I have the domain cookie for the phpbb file to correspond with both Nucleus and phpBB. Because I use a subdomain for both, I just used .domain.com for the phpBB cookie. I removed all cookie information from the Nucleus global settings. Once again, not sure if this matters, but this is what I did.

Next I made sure in global settings in Nucleus that you allow new members, allow members to login, allow users to change details, ect....

I then tested this with creating a new user in the phpBB forum that wasn't already in Nucleus. (Making sure you are already logged out of Nucleus), I proceeded to just go over to Nucleus and the new user was logged in! ! !

I know this because I placed the login form on the page so that it would give me the login form if I was logged out and 'logged in as newuser !' if I was logged in.

Here is the code that I used. I hope it helps people out a bit.....

Code is at http://forum.nucleuscms.org/viewtopic.php?p=29201#29201

Thanks,

Trent (& Andrew!)

_________________
Life Through The Eyes Of Trent Adams!


Last edited by Trent on Tue Feb 08, 2005 12:07 am; edited 4 times in total

Back to top

View user's profile Send private message Visit poster's website ICQ Number
Trent
Nucleus Guru
Nucleus Guru


Joined: 04 Oct 2002
Posts: 1555
Location: Alberta, Canada

Post Posted: Sun Jan 23, 2005 3:38 am   Post subject:
Reply with quote

Just a quick note, you can also change the default installation to allow users to login to the admin area by default by changing line 75 to:

Code:
$res=MEMBER::create($userdata['username'], $userdata['username'], $userdata['user_password'], $userdata['user_email'], $userdata['user_website'], 0, 1, '');


I actually did that because that just seems more usefull to me! ! !

Trent

_________________
Life Through The Eyes Of Trent Adams!

Back to top

View user's profile Send private message Visit poster's website ICQ Number
Trent
Nucleus Guru
Nucleus Guru


Joined: 04 Oct 2002
Posts: 1555
Location: Alberta, Canada

Post Posted: Sun Jan 23, 2005 4:57 am   Post subject:
Reply with quote

Andrew,

Is there a way to use something like:

Code:
TEAM::create($userdata['username'], 1, 0);


or

Code:
TEAM::add($userdata['username'], 1, 0);


to get the member added to a blog team? Is there a TEAM class?

Trent

_________________
Life Through The Eyes Of Trent Adams!

Back to top

View user's profile Send private message Visit poster's website ICQ Number
Frankenstein
Nucleus Expert


Joined: 01 Mar 2004
Posts: 257

Post Posted: Sun Jan 23, 2005 7:47 am   Post subject:
Reply with quote

Couple follow up notes.

It may require a couple small changes, but I believe it may be possible for the plugin to work with phpBB installations in other databases. It should work with phpBB installations using a different server or different DBMS. The only requirements are that the DB server be accessible from the web server, and the servers the forum and weblog are on share a web path such that the cookies from one are visible on the other.

The original version of the code that you altered to allow logging onto the admin area (updated for the final version) looked like
Code:
      $res=MEMBER::create($userdata['username'], $userdata['username'], "", $userdata['user_email'], $userdata['user_website'], 0, $CONF['NewMemberCanLogon'], '');


The problem with this is it would init the password to md5("") if no changes were made to the core (such as ExtAuth), and allow someone to login to an autogenerated account using a blank password. This would be a bad thing(tm). However, with ExtAuth, this is exactly what would be desired, as it would indicate that this login is supposed to be authenticated externally. What the current code does is it sets the password stored in the Nucleus database to the md5 of the password stored in the phpBB database, which is the md5 of the user's cleartext password. The following would use an appropriate system configuration variable (need to add $CONF to the globals at the top of the function)

Code:
      $res=MEMBER::create($userdata['username'], $userdata['username'], $userdata['user_password'], $userdata['user_email'], $userdata['user_website'], 0, $CONF['NewMemberCanLogon'], '');


If you wanted the password to be the same in nucleus as in phpBB (usually), add the following two lines to the end of the event_PostAuthentication function.
Code:
         $member->password=$userdata['user_password'];
         $member->write();


ExtAuth integration would be better, but this will have to do, as ExtAuth requires core changes.

To answer your question, the syntax you would need to autoadd a member to a team is roughly the following:

Code:
         $autoblog=$manager->getBlog($autojoin_blogid);//$autojoin_id is the ID of the blog to automatically add members to.  Possibly a config variable
         $autoblog->addTeamMember($member->getID(), 0);


These would be added just after the line reading
Code:
         ACTIONLOG::add(INFO, "{$userdata['username']} autogenerated by NP_phpBB");


Alternately, create a new plugin that subscribes to the PostRegister event, and have it execute the same actions (more or less). This would be the 'correct' way to add the functionality.

One question I have for the community as a whole is if there is a demand for the topic creation functionality that is implemented in the NP_punBB plugin? It shouldn't be too hard to create an equivilent, but if there is no demand for it, why add the feature?

Back to top

View user's profile Send private message
Trent
Nucleus Guru
Nucleus Guru


Joined: 04 Oct 2002
Posts: 1555
Location: Alberta, Canada

Post Posted: Sun Jan 23, 2005 4:45 pm   Post subject:
Reply with quote

As for the punBB functionality, I don't need it !

Code:
      $res=MEMBER::create($userdata['username'], $userdata['username'], $userdata['user_password'], $userdata['user_email'], $userdata['user_website'], 0, $CONF['NewMemberCanLogon'], '');


That code didn't allow new member to login to the admin area even with the $conf in the globals. It would only work if I changed $CONF['NewMemberCanLogon'] back to 1 instead......

Code:
         //Couldn't find the member in the nucleus database, so create a record for him/her.
      $res=MEMBER::create($userdata['username'], $userdata['username'], $userdata['user_password'], $userdata['user_email'], $userdata['user_website'], 0, 1, '');
         if(1!==$res){
            ACTIONLOG::add(WARNING, "NP_phpBB: {$res} autogenerating {$userdata['username']}: {$userdata['user_email']}, {$userdata['user_website']}");
         $autoblog=$manager->getBlog($autojoin_blogid);//$autojoin_id is the ID of the blog to automatically add members to.  Possibly a config variable
         $autoblog->addTeamMember($member->getID(), 0);


I wasn't sure if this was the place for the $autoblog code....but it didn't work for me. Not even when the previous code was switched back to allow the member to login......
Code:

      $member->loggedin = 1;
         $member->password=$userdata['user_password'];
         $member->write();


I placed the password stuff at the end of the function and I don't know how to test if it is working or not! ! !

I guess the 2 big things would be getting the code to add member to a specified team and to get them to login to the admin area without my 'hack' !! ! !!

Trent

_________________
Life Through The Eyes Of Trent Adams!

Back to top

View user's profile Send private message Visit poster's website ICQ Number
Frankenstein
Nucleus Expert


Joined: 01 Mar 2004
Posts: 257

Post Posted: Sun Jan 23, 2005 7:35 pm   Post subject:
Reply with quote

Did you add $conf or $CONF? Case matters in this case. Also, the configuration variable in question (Admin: General Settings: Member Settings: Login Allowed for User-Created accounts) would need to be set yes.

The autoblog code got added in the wrong place. Where you added it was in the error handling code for if the autogeneration fails. Move it about 5 lines down, after the next ACTONLOG:add() call.

You can test the password code by logging out from PHPbb, then going to Nucleus and logging in with a username/password that has been autoauthenticated. This won't log you into phpBB, but it should allow you to log into Nucleus.

I'll move the plugin autojoin code out of this discussion, as it's something of a tangent.

--Andrew Black

Back to top

View user's profile Send private message
Trent
Nucleus Guru
Nucleus Guru


Joined: 04 Oct 2002
Posts: 1555
Location: Alberta, Canada

Post Posted: Wed Jan 26, 2005 2:20 am   Post subject:
Reply with quote

I have changed the first post to reflect the recent changes in this plugin from Andrew to avoid confusion in what to use!

Trent

_________________
Life Through The Eyes Of Trent Adams!

Back to top

View user's profile Send private message Visit poster's website ICQ Number
Trent
Nucleus Guru
Nucleus Guru


Joined: 04 Oct 2002
Posts: 1555
Location: Alberta, Canada

Post Posted: Thu Feb 03, 2005 4:26 pm   Post subject:
Reply with quote

Andrew,

I was wondering if we can also grab the phpBB user profile address for this plugin? That is another one that would be great if we could store the user's site when they move over to Nucleus as their phpBB profile page. That way, there can be avators, etc...


Trent

_________________
Life Through The Eyes Of Trent Adams!

Back to top

View user's profile Send private message Visit poster's website ICQ Number
Trent
Nucleus Guru
Nucleus Guru


Joined: 04 Oct 2002
Posts: 1555
Location: Alberta, Canada

Post Posted: Thu Feb 03, 2005 10:43 pm   Post subject: Further NP_phpBB mods......
Reply with quote

Ok.....idea here for making this integration plugin more integrated! I had the idea of adding the profile URL from the forum as the URL for the Nucleus website for the user.

While I know Andrew most likely has a better way to do this, I am just going to paste the code that I have changed from the original plugin here until he pastes his thoughts on the matter!

INTEGRATING FORUM PROFILE INTO NUCLEUS

Right off the bat, if you already have this plugin installed, you must uninstall it before installing this changed version as it has additional install options!

Step 1

Open up the orginal NP_phpBB code in a text editor and find around line 49 and change it from:

Code:
   function install() {
       $this->createOption('phpbbRootPath','File system path to the phpBB','text','../phpBB2/');
       $this->createOption('enable','Enable phpBB authentication','yesno','no');
   }


To:

Code:
   function install() {
       $this->createOption('phpbbRootPath','File system path to the phpBB','text','../phpBB2/');
       $this->createOption('enable','Enable phpBB authentication','yesno','no');
       $this->createOption('phpbburl','URL of forum (with ending slash /)','text','http://forum.yoursite.com/');
   }


This adds plugin option to place the URL of your forum ending with a slash.

Step 2

Find around line 75 and change it from:

Code:
         //Couldn't find the member in the nucleus database, so create a record for him/her.
      $res=MEMBER::create($userdata['username'], $userdata['username'], $userdata['user_password'], $userdata['user_email'], $userdata['user_website'], 0, $CONF['NewMemberCanLogon'], '');


To:

Code:
         //Couldn't find the member in the nucleus database, so create a record for him/her.
   $phpbbweburl = $this->getOption('phpbburl');
   $phpbbprofileURL = "profile.php?mode=viewprofile&u=";
   $userwebsite = $phpbbweburl.$phpbbprofileURL.$userdata['user_id'];

      $res=MEMBER::create($userdata['username'], $userdata['username'], $userdata['user_password'], $userdata['user_email'], $userwebsite, 0, $CONF['NewMemberCanLogon'], '');


This takes the profile address of the forum member and adds that URL as the website URL for the new Nucleus user.

Step 4: (Optional)

Change your member skin for Nucleus to have something like:

Code:
<ul>
  <li>Real name: <b><%member(realname)%></b></li>
  <li>Find out more about <b><%member(realname)%></b> at <a href="<%member(url)%>">their profile page!</a> ! ! !</li>
 </ul>


Conclusion

This further increases the integration of this plugin to have a full community! Since the information is best kept in the profile at the forum (allows you to add even more info easily through phpBB MODS), you can just direct people to that information!

While the code might not be perfect, I ask the following questions:

What do you think? Any suggestions? Any helpful hints? Any problems?

Thanks,

Trent

_________________
Life Through The Eyes Of Trent Adams!

Back to top

View user's profile Send private message Visit poster's website ICQ Number
Frankenstein
Nucleus Expert


Joined: 01 Mar 2004
Posts: 257

Post Posted: Sat Feb 05, 2005 8:47 pm   Post subject:
Reply with quote

*shrugs*

I batted this around a fair amount, and produced the following

Code:
<?php
/**
  * This file includes()s a pair of libraries from the phpBB codebase
  * (includes/constants.php and includes/sessions.php), uses functions from a
  * third (includes/functions.php) and the classes from a fourth and fifth
  * (include/db.php and db/*.php)
  * These includes are used to allow this plugin to authenticate against the
  * phpBB cookies, with the help of assorted types of glue.
  * includes/functions.php can't be included due to a function naming conflict
  * (redirect()). One function has been replaced with a glue version
  * (message_die), and two others been borrowed (encode_ip and
  * phpbb_clean_username).
  **/

function message_die($msg_code, $msg_text = '', $msg_title = '', $err_line = '', $err_file = '', $sql = '')
{
   doError('phpBB Error: '.$msg_text);
}

function encode_ip($dotquad_ip)
{
   $ip_sep = explode('.', $dotquad_ip);
   return sprintf('%02x%02x%02x%02x', $ip_sep[0], $ip_sep[1], $ip_sep[2], $ip_sep[3]);
}

function phpbb_clean_username($username)
{
   $username = htmlspecialchars(rtrim(trim($username), "\\"));
   $username = substr(str_replace("\\'", "'", $username), 0, 25);
   $username = str_replace("'", "\\'", $username);

   return $username;
}

class NP_phpBB extends NucleusPlugin {
   function getEventList() { return array('PostAuthentication'); }
   function getName() { return 'phpBB User Integration'; }
   function getAuthor() { return 'Andrew Black'; }
   function getURL() { return 'http://www.yoursite.com/'; }
   function getVersion() { return '1.0 - beta'; }
   function supportsFeature($what) {
      switch($what)
      { case 'SqlTablePrefix':
            return 1;
         default:
            return 0; }
   }

   function install() {
       $this->createOption('phpbbRootPath','File system path to the phpBB','text','../phpBB2/');
       $this->createOption('enable','Enable phpBB authentication','yesno','no');
   }
   
   function getDescription() { return 'phpBB integration plugin.'; }
   
   function doSkinVar($skinType){
      global $db, $board_config, $userdata, $phpEx, $starttime;
      static $loopblock=0;
     
      if('member'!=$skinType)
         return;
     
      if('no'==$this->getOption('enable')){
         //Try to fallback if the plugin shut itself down
         if(!$loopblock){
            global $skinid;
            $loopblock=1;
            $skin_name = 'fallback/' . SKIN::getNameFromId($skinid);
            $skin = SKIN::createFromName($skin_name);
           
            if ($skin->isValid){
               $skin->parse($skinType);
               return;
            }
         }
           
         doError($skinType.'unavailable due to phpBB integration error. No fallback found.');
      }
     
      global $memberinfo;
      $name=$memberinfo->getDisplayName();
     
      //Check if user exists in phpBB db?
     
      //The initial thought had been to include the profile directly,
      //But there's a namespace conflict with the nucleus template class.
      //Therefore, we'll redirect to...
     
$url=append_sid("profile.php?mode=viewprofile&".POST_USERS_URL."=".$name, true);
     
      //Include a couple phpBB libraries
      $phpbb_root_path=$this->getOption('phpbbRootPath');
      include_once($phpbb_root_path.'includes/constants.'.$phpEx);
      include_once($phpbb_root_path.'includes/sessions.'.$phpEx);
      //Just in case they're needed (I not certain if they are or aren't)
     
      //Then borrow the phpBB redirect(), skipping a check
      if (!empty($db))
      {
         $db->sql_close();
      }
     
      $server_protocol = ($board_config['cookie_secure']) ? 'https://' : 'http://';
      $server_name = preg_replace('#^\/?(.*?)\/?$#', '\1', trim($board_config['server_name']));
      $server_port = ($board_config['server_port'] <> 80) ? ':' . trim($board_config['server_port']) : '';
      $script_name = preg_replace('#^\/?(.*?)\/?$#', '\1', trim($board_config['script_path']));
      $script_name = ($script_name == '') ? $script_name : '/' . $script_name;
      $url = preg_replace('#^\/?(.*?)\/?$#', '/\1', trim($url));
     
      // Redirect via an HTML form for PITA webservers
      if (@preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')))
      {
         header('Refresh: 0; URL=' . $server_protocol . $server_name . $server_port . $script_name . $url);
         echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><meta http-equiv="refresh" content="0; url=' . $server_protocol . $server_name . $server_port . $script_name . $url . '"><title>Redirect</title></head><body><div align="center">If your browser does not support meta redirection please click <a href="' . $server_protocol . $server_name . $server_port . $script_name . $url . '">HERE</a> to be redirected</div></body></html>';
         exit;
      }
      // Behave as per HTTP/1.1 spec for others
      header('Location: ' . $server_protocol . $server_name . $server_port . $script_name . $url);
      exit;
   }
   
   function event_PostAuthentication($data) {
      global $member, $manager, $action, $CONF, $userdata;
     
      if($data['loggedIn'] || ('no'==$this->getOption('enable')))
         return;
      //Don't mess with the member object if it's authenticated or the plugin is disabled.
     
      $this->_link_phpBB();
     
      if(ANONYMOUS==$userdata['user_id'] || 'logout' == $action)
         return;//since we don't have a session
     
      //At this point, we've determined who that the user is who he/she says he/she is.
      //Now we need to load his/her nucleus user record.
      if($member->readFromName($userdata['username'])){
         ACTIONLOG::add(DEBUG, "{$userdata['username']} externally authenticated through NP_phpBB");

         //Change to INFO only if you want to spam the message log with these messages,
         //as one will be generated every time a page is loaded by a logged in member.
         //Message is included as a debugging tool.
      }else{
         //Couldn't find the member in the nucleus database, so create a record for him/her.
      $res=MEMBER::create($userdata['username'], $userdata['username'], $userdata['user_password'], $userdata['user_email'], $userdata['user_website'], 0, $CONF['NewMemberCanLogon'], '');
         if(1!==$res){
            ACTIONLOG::add(WARNING, "NP_phpBB: {$res} autogenerating {$userdata['username']}: {$userdata['user_email']}, {$userdata['user_website']}");
            doError('NP_phpBB: Unable to set up tie account.  Please contact the forum administrator.');
         }
         $member->readFromName($userdata['username']);
         $manager->notify('PostRegister',array('member' => &$member));
         ACTIONLOG::add(INFO, "{$userdata['username']} autogenerated by NP_phpBB");
      }
      $member->loggedin = 1;
         $member->password=$userdata['user_password'];
         $member->write();
      //Because we have authenticated the member, this flag needs to be set.
   }
   
   function _link_phpBB (){
      global $db, $board_config, $userdata, $phpEx, $starttime;
      //the following line is a hack to tell the phpBB libraries that we are part of the phpBB codebase
      define('IN_PHPBB', 'Nucleus_Plugin');
         //standard value is true.  I'm using something else to distinguish us if needed
     
      $phpbb_root_path=$this->getOption('phpbbRootPath');
     
      $board_config = array();
      $userdata = array();
     
      if(!(include($phpbb_root_path . 'extension.inc')))
      {
         $this->setOption('enable','no');//Turn ourself 'off' since we aren't functional
         ACTIONLOG::add(ERROR, "NP_phpBB: unable to include extension.inc");
         return;
      }
     
      include($phpbb_root_path.'config.'.$phpEx);
      include($phpbb_root_path.'includes/constants.'.$phpEx);
      include($phpbb_root_path.'includes/sessions.'.$phpEx);
      include($phpbb_root_path.'includes/db.'.$phpEx);
      sql_connect();
         //Reset the last opened link identifier.
         //The phpBB db classes cache their link internally rather
         //than assuming it's the last opened.
     
      $user_ip = encode_ip(serverVar('REMOTE_ADDR'));
     
      // Begin phpBB config loading (borrowed from phpBB's common.php)
      $sql = "SELECT *
         FROM " . CONFIG_TABLE;
      if( !($result = $db->sql_query($sql)) )
      {
         message_die(CRITICAL_ERROR, "Could not query config information", "", __LINE__, __FILE__, $sql);
      }
     
      while ( $row = $db->sql_fetchrow($result) )
      {
         $board_config[$row['config_name']] = $row['config_value'];
      }
      //end phpbb config loading
     
      $userdata=session_pagestart($user_ip, PAGE_INDEX);
     
      //The next few lines handle the logout command
      global $action, $manager;
      if('logout'==$action && $userdata['session_logged_in'] )
      {
         session_end($userdata['session_id'], $userdata['user_id']);
         $manager->notify('Logout',array('username' => $userdata['username']));
      }
   }
}
?>


Usual caviet of being untested, so there's probably a syntax error or such in it.

The route I have chosen is to use a profile skinvar, rather than borrowing the url field. This is actually a 2 part process.

The first step is to clone the skin you wish to alter as fallback/skinname, then delete all the elements except the Member Details skinpart. This skin will be used if there are problems with the plugin.

The second step is to alter the original member details skinpart to read
Code:
<%phpBB()%>

This turns the profile page into a redirect to the phpBB profile page.

Back to top

View user's profile Send private message
Post new topic This topic is locked: you cannot edit posts or make replies.
Display posts from previous:   

Goto page 1, 2, 3, 4, 5  Next

Page 1 of 5

All times are GMT + 1 Hour

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2002 phpBB Group