• crazyvipa

    (@crazyvipa)


    Is this process simple? No.
    Is this process completely useful? No.
    But it works.

    All I needed was session data from phpBB3, I did not need to copy my forum’s 18k users to another table while it sat there. The blog is intended for just admins to post (not that hard to just type in the login url and bookmark it)

    First, the concept. WordPress and phpBB almost seems identical in the programming — almost like it was the same programmer. The result of this is obvious across google… lots of errors pop off when you try to just integrate by copy/pasting. If you are like me, you’ll enjoy this little project.

    What we need is:
    phpBB3 Integration Code found all over the internet:

    /* phpBB3 Integration */
    				define('IN_PHPBB', true);
    				$phpbb_root_path = '/your/absolute/path/to/forum/'; /* As a 'rule' I usually try to define absolute paths */
    				$phpEx = 'php';
    				include($phpbb_root_path . 'common.' . $phpEx);
    				$user->session_begin();
    				$auth->acl($user->data);
    				$user->setup();
    			/* End phpBB3 Integration */

    External Class File – We need this to store the data, going to use singleton..

    class UserData {
    		private static $_instance;
    
    		public $user_id;
    		public $Data;
    
    		function __construct($_user) {
    			$this->user_id = $_user['user_id'];
    			$this->Data = $_user;
    		}
    
    		public static function getInstance($_user = null) {
    	        if (is_null(self::$_instance)) {
    	            self::$_instance = new self($_user);
    	        }
    	        return self::$_instance;
    	    }
    
    		public function __get($magic) {
    			return $this->Data[$magic];
    		}
    		public function changePostCount($Inc = true, $Total = 1) {
    			if ($Inc):
    				$proc = '+';
    			else:
    				$proc = '-';
    			endif;
    			mysql_query("UPDATE USER_TABLE SET user_posts = user_posts {$proc} {$Total} WHERE user_id = {$this->user_id} LIMIT 1;");
    		}
    		public function isAuthed($level) {
    			$level = (int) $level;
    			if (!$this->is_registered) { return false; } // Not logged in, automatic boot out :)
    
    			$cur_rank = $this->user_rank; // We use magic here, so lets just call once.
    			// Sorry, not going to post the 'level' info. $level is based on a internal idea of what the user is. You can change to this calculate with any number (ie: user_posts or group_id) -- not sure about group_id, I think its user_group, but the 'magic' session data is in the same format as the phpbb table cols.
    			switch ($level):
    				case 0: // Are they registered?
    					$authed = true; // already checked above, no need to redo..
    				break;
    			endswitch;
    
    			return $authed;
    		}
    	}
    	$UserData = UserData::getInstance($user->data);

    Go ahead and make a file with that class info above. Feel free to change as needed. You need to look through the code and change to fit your needs.

    Now that we have these 2 pieces of code, lets put them where they need to be. In WordPress, open the index.php file. At the *very top* use code:

    index.php

    /* phpBB3 Integration */
    	include('/path/to/class/file.php');
    	define('IN_PHPBB', true);
    	$phpbb_root_path = '/your/absolute/path/to/forum/'; /* As a 'rule' I usually try to define absolute paths */
    	$phpEx = 'php';
    	include($phpbb_root_path . 'common.' . $phpEx);
    	// Start session management
    	$user->session_begin();
    	$auth->acl($user->data);
    	$user->setup();
    	unset($user);unset($auth);
    /* End phpBB3 Integration */

    That is all we need to do to the index file. If you launch this as is, you’ll get some errors. This is has nothing to do with phpBB, it is wordpress we are hacking into, not phpBB. No need to modify phpBB at all. Doing so will just cause issues.

    I’m guessing you have a project file opened up in textmate or dreamweaver… close it. Open up the entire wordpress project by itself… we don’t want to screw anything up in something external.

    Do a search for “$db” after search completed, replace ALL OF THEM, (even the ones that are $dbh and such) with $new_wp_db (or something unique that only wordpress would be using).

    Now do a search for: “make_clickable” .. do replace all with “new_wp_make_clickable” .. you should see a few in there including the original function. There is one that ‘scared’ me because it was “‘make_clickable‘” .. but change that one also.

    Guess what… mission complete. Within your theme files, just do a call to the UserData class by “UserData::getInstance()->user_id” (or whatever you are trying to get to)… and vola!

    There may be some situations with session loss, but… honestly… it beats making a huge duplicate table in mysql… I mean seriously, what is the point of “integration” when all you are doing is copying the data tables… not worth it. And not the smartest thing I’ve ever seen done.

    I hope this helps someone, and I know the code is rough. It isn’t the easiest thing in the world either. You’ll have to make certain sacrifices, such as coding in your OWN user auths. For example, the comment system.

    In reality, I needed this blog to be attached to my forum. I wanted the users to be able to comment, and nothing else. So it was easy enough to look through the code and make my own. If you intend to do this, make sure you turn off the requirement for users to be logged in to comment (in wordpress).

    Yes, it is a bad idea to change WP’s variables, so make sure you won’t be doing any modifications after your phpBB3 integration.

    If you *do* need to make modifications… always make sure you write down what variables you changed. Before you upload a mod, make sure the vars get changed. Then everything will work fine.

Viewing 1 replies (of 1 total)
  • Thread Starter crazyvipa

    (@crazyvipa)

    I made a typo, sorry:

    /* phpBB3 Integration */
    	define('IN_PHPBB', true);
    	$phpbb_root_path = '/your/absolute/path/to/forum/'; /* As a 'rule' I usually try to define absolute paths */
    	$phpEx = 'php';
    	include($phpbb_root_path . 'common.' . $phpEx);
    	// Start session management
    	$user->session_begin();
    	$auth->acl($user->data);
    	$user->setup();
    	include('/path/to/class/file.php'); /* Oops, thats what I get for rushing. Include at the bottom */
    	unset($user);unset($auth);
    /* End phpBB3 Integration */
Viewing 1 replies (of 1 total)

The topic ‘Access phpBB3 Session WordPress’ is closed to new replies.