New Community Forums are coming. Watch this space for news.
Subscribe: RSS
  • Hi all,

    I am currently converting an older site including a phpBB forum to ModX. Given the forum size i am not keen on migrating to another forum script; and must say i quite like phpBB too!

    I am not trying to integrate phpBB and MODX (as it's been discussed in the past, e.g. http://forums.modx.com/forums/thread/48916/phpbb-and-modx-integration) with a full bridge, but just need to use phpBB sessions into ModX pages.

    I have found a solution which seems to work fine. Must say it took me longer than i expected to implement (i am new to Modx and still have a lot to learn !). In particular have had issues with snippets and MODX caching.
    I am including below a copy of my solution and code, in case it would be helpful to others with similar needs. Plse feel free to amend AND moreover UPGRADE or IMPROVE as you see fit !

    MODX version : Revolution 2.2.8
    PhpBB version : 3.0.11
    Forum url : www.example.com/forum/

    Snippet sessionphpBB (a real basic class, you can expand as you need) :

    <?php
    class MyPhpBBsession {
               
        public function __construct()
        {       
            global $phpbb_root_path, $phpEx, $user, $db, $config, $cache;
            
            define('IN_PHPBB', true);
            $phpbb_root_path = './forum/';
            $phpEx = substr(strrchr(__FILE__, '.'), 1);
            include($phpbb_root_path . 'common.' . $phpEx);
    		// Start phpBB session management
            $user->session_begin();
    		// Setup the auth/permissions for this user
    		$auth->acl($user->data);
    		// setup the user-specific settings, style and language (optional)
    		// $user->setup(); 
    		
        }
           
        public function getid()
        {
            global $phpbb_root_path, $phpEx, $user, $db, $config, $cache;
            return $user->data['user_id'];
        }   
    	
    	public function getusername()
        {
            global $phpbb_root_path, $phpEx, $user, $db, $config, $cache;
            return $user->data['username'] ;		 
        }
    	
    	public function urllogout()
        {
            global $phpbb_root_path, $phpEx, $user, $db, $config, $cache;
            $url_logout= append_sid("/forum/ucp.$phpEx", 'mode=logout', true, $user->session_id) ;
    		return $url_logout;
    		 
        }
    }


    Snippet user_loginout :

    <?php
    $pbbuser = new MyPhpBBsession ();
    $myusername=$pbbuser->getusername();
    
    if ($myusername!='Anonymous') {
    $my_user_title = 'Logout [ '.$myusername.' ]' ;
    $my_user_link =  $pbbuser->urllogout() ;
    $my_link_add = '';
    $my_private = '[[$members_private_message]]';
    
    $modx->setPlaceholder('loginout_title',$my_user_title);
    $modx->setPlaceholder('loginout_url',$my_user_link);
    $modx->setPlaceholder('mydata_url',$my_link_add);
    $modx->setPlaceholder('myprivate_content',$my_private);
    
    //$output = '<div style="display:none">Welcome '.$myusername.'</div>';
    //return $output;	
    
    }
    
    else {
    
    $my_user_title = 'Login' ;
    $my_user_link = '#login-form';
    $my_link_add = 'data-toggle="modal"';
    $my_private = '[[$members_message_login]]';
    
    $modx->setPlaceholder('loginout_title',$my_user_title);
    $modx->setPlaceholder('loginout_url',$my_user_link);
    $modx->setPlaceholder('mydata_url',$my_link_add);
    $modx->setPlaceholder('myprivate_content',$my_private);
    
    	if (!empty($tpl)) {$output = $modx->getChunk($tpl); return $output; }
    	else {$output='login_form chunk not found'; return $output;}
    }


    As phpBB session code needs to be first, i am including it first in my templates, example :
    [[!sessionphpBB]]
    [[$template_header]]
    
    [[!user_loginout? &tpl=`login_form`]]
    
    [[$navbar_page]] 
    <div class="main-container">
    [[$intro]] 	
    [[*content]]
    [[$myfooter]]
    </div><!-- end main-container -->  		
    [[$template_footer]]
    


    A simple chunk "userloginout"to add a login link or logout[user_name] as with phpBB :
    <a href="[[+loginout_url]]" [[+mydata_url]]>[[+loginout_title]]</a>

    which can e.g. be called into your main menu :
    <li>[[$userloginout]]</li>


    and a login form (as a popup window, using bootstrap css/templates):

    <div id="login-form" class="modal hide fade in" style="display: none;">
    		
    			<div class="modal-header">
    				<a class="close" data-dismiss="modal">×</a>
    				<h3>Sign In</h3>
    			</div>
    			
    			<div class="modal-body">
    				<form method="post" action="/forum/ucp.php?mode=login">
    
    				User : <br /><input type="text" name="username" size="8" /><br />
    				Password * : <br /><input type="password"  name="password" size="8" />
    
    				     
    
    				<input class="btn btn-large btn-purple" type="submit" name="login"  value="Login" />
    
    				<input type="hidden" name="redirect" value="[[++site_url]]forum/" />
    
    				<label id="autologin_label" for="autologin"><input type="checkbox" name="autologin" id="autologin" /> <em>Log me on automatically each visit</em></label>
    				</form>
    				<a href="/forum/ucp.php?mode=sendpassword"class="btn"><em>* I forgot my password</em></a>
    			</div>
    			
    			<div class="modal-footer">
    				
    				Not registered yet ?   
    				<a href="[[++site_url]]forum/ucp.php?mode=register" class="btn btn-purple">Sign Up !</a>
    				
    			</div>
    		</div>


    At this stage i am using this code to display a login/logout[user_name] link in my MODX pages menu, displaying a private message and hiding some ads (using visibility:hidden for the later) to logged in members only. It is possible to login or logout from any MODX or PhpBB page. Using the MODX plugin "getfeed", i can develop pages with the latest posts from the forum or its sections of interest to particular members (still need to double check whether only the authorized forums/posts are displayed for a given member). Modx templates/phpBB themes used are looking alike (hence a seamingless navigation across the site) but no actual integration between the 2 scripts (not needed in my case).
    Please note i am NOT using MODX authorizations/users here at all. This would be a much bigger endeavour (well above my skills and knowledge); i am specifically concerned about potential uncompatibilities and/or need to rename some variables which would require a "deep dive" into MODX and PhpBB main coding...

    Hope this is an helpful starting point [ed. note: justinet last edited this post 5 years, 6 months ago.]
    • This looks like a major project, congrats on reaching a solution!

      I wonder how things are working, and do you think this solution would be good for a new bbs rather than a converted, existing bbs.

      Also, I am a bit confused about this statement you made, "Please note i am NOT using MODX authorizations/users here at all. " Earlier you said users could log in or out on any page. So i don't quite know what you mean about not using modx authorizations...
      • Yes, this is using phpBB sessions ONLY i.e. users can login on any MODX page with their phpBB references.
        In other words there is NO BRIDGE established here between phpBB and MODX data bases.

        For a new project developed with MODX i would rather use MODX native bulletin boards
        capabilities (new), as it's done with this forum for instance.
        • Ok I understand your thinking, and agree. Discuss seems to be the future of modx...hope your project works out well, pls update us when you can. Hope your modx experience is positive!

          Quote from: justinet at Sep 22, 2013, 09:23 AM
          Yes, this is using phpBB sessions ONLY i.e. users can login on any MODX page with their phpBB references.
          In other words there is NO BRIDGE established here between phpBB and MODX data bases.

          For a new project developed with MODX i would rather use MODX native bulletin boards
          capabilities (new), as it's done with this forum for instance.
          • Hi all,

            I am currently converting an older site including a phpBB forum to ModX. Given the forum size i am not keen on migrating to another forum script; and must say i quite like phpBB too!

            I am not trying to integrate phpBB and MODX (as it's been discussed in the past, e.g. http://forums.modx.com/forums/thread/48916/phpbb-and-modx-integration) with a full bridge, but just need to use phpBB sessions into ModX pages.

            I have found a solution which seems to work fine. Must say it took me longer than i expected to implement (i am new to Modx and still have a lot to learn !). In particular have had issues with snippets and MODX caching.
            I am including below a copy of my solution and code, in case it would be helpful to others with similar needs. Plse feel free to amend AND moreover UPGRADE or IMPROVE as you see fit !

            MODX version : Revolution 2.2.8
            PhpBB version : 3.0.11
            Forum url : www.example.com/forum/

            Snippet sessionphpBB (a real basic class, you can expand as you need) :

            <?php
            class MyPhpBBsession {
                       
                public function __construct()
                {       
                    global $phpbb_root_path, $phpEx, $user, $db, $config, $cache;
                    
                    define('IN_PHPBB', true);
                    $phpbb_root_path = './forum/';
                    $phpEx = substr(strrchr(__FILE__, '.'), 1);
                    include($phpbb_root_path . 'common.' . $phpEx);
            		// Start phpBB session management
                    $user->session_begin();
            		// Setup the auth/permissions for this user
            		$auth->acl($user->data);
            		// setup the user-specific settings, style and language (optional)
            		// $user->setup(); 
            		
                }
                   
                public function getid()
                {
                    global $phpbb_root_path, $phpEx, $user, $db, $config, $cache;
                    return $user->data['user_id'];
                }   
            	
            	public function getusername()
                {
                    global $phpbb_root_path, $phpEx, $user, $db, $config, $cache;
                    return $user->data['username'] ;		 
                }
            	
            	public function urllogout()
                {
                    global $phpbb_root_path, $phpEx, $user, $db, $config, $cache;
                    $url_logout= append_sid("/forum/ucp.$phpEx", 'mode=logout', true, $user->session_id) ;
            		return $url_logout;
            		 
                }
            }


            Snippet user_loginout :

            <?php
            $pbbuser = new MyPhpBBsession ();
            $myusername=$pbbuser->getusername();
            
            if ($myusername!='Anonymous') {
            $my_user_title = 'Logout [ '.$myusername.' ]' ;
            $my_user_link =  $pbbuser->urllogout() ;
            $my_link_add = '';
            $my_private = '';
            
            $modx->setPlaceholder('loginout_title',$my_user_title);
            $modx->setPlaceholder('loginout_url',$my_user_link);
            $modx->setPlaceholder('mydata_url',$my_link_add);
            $modx->setPlaceholder('myprivate_content',$my_private);
            
            //$output = '<div style="display:none">Welcome '.$myusername.'</div>';
            //return $output;	
            
            }
            
            else {
            
            $my_user_title = 'Login' ;
            $my_user_link = '#login-form';
            $my_link_add = 'data-toggle="modal"';
            $my_private = '';
            
            $modx->setPlaceholder('loginout_title',$my_user_title);
            $modx->setPlaceholder('loginout_url',$my_user_link);
            $modx->setPlaceholder('mydata_url',$my_link_add);
            $modx->setPlaceholder('myprivate_content',$my_private);
            
            	if (!empty($tpl)) {$output = $modx->getChunk($tpl); return $output; }
            	else {$output='login_form chunk not found'; return $output;}
            }


            As phpBB session code needs to be first, i am including it first in my templates, example :
            
            
            
            
            
             
            <div class="main-container">
             	
            
            
            
            </div><!-- end main-container -->  		
            
            


            A simple chunk "userloginout"to add a login link or logout[user_name] as with phpBB :
            <a href="" ></a>

            which can e.g. be called into your main menu :
            <li></li>


            and a login form (as a popup window, using bootstrap css/templates):

            <div id="login-form" class="modal hide fade in" style="display: none;">
            		
            			<div class="modal-header">
            				<a class="close" data-dismiss="modal">×</a>
            				<h3>Sign In</h3>
            			</div>
            			
            			<div class="modal-body">
            				<form method="post" action="/forum/ucp.php?mode=login">
            
            				User : <br /><input type="text" name="username" size="8" /><br />
            				Password * : <br /><input type="password"  name="password" size="8" />
            
            				     
            
            				<input class="btn btn-large btn-purple" type="submit" name="login"  value="Login" />
            
            				<input type="hidden" name="redirect" value="https://forums.modx.com/forum/" />
            
            				<label id="autologin_label" for="autologin"><input type="checkbox" name="autologin" id="autologin" /> <em>Log me on automatically each visit</em></label>
            				</form>
            				<a href="/forum/ucp.php?mode=sendpassword"class="btn"><em>* I forgot my password</em></a>
            			</div>
            			
            			<div class="modal-footer">
            				
            				Not registered yet ?   
            				<a href="https://forums.modx.com/forum/ucp.php?mode=register" class="btn btn-purple">Sign Up !</a>
            				
            			</div>
            		</div>


            At this stage i am using this code to display a login/logout[user_name] link in my MODX pages menu, displaying a private message and hiding some ads (using visibility:hidden for the later) to logged in members only. It is possible to login or logout from any MODX or PhpBB page. Using the MODX plugin "getfeed", i can develop pages with the latest posts from the forum or its sections of interest to particular members (still need to double check whether only the authorized forums/posts are displayed for a given member). Modx templates/phpBB themes used are looking alike (hence a seamingless navigation across the site) but no actual integration between the 2 scripts (not needed in my case).
            Please note i am NOT using MODX authorizations/users here at all. This would be a much bigger endeavour (well above my skills and knowledge); i am specifically concerned about potential uncompatibilities and/or need to rename some variables which would require a "deep dive" into MODX and PhpBB main coding...

            Hope this is an helpful starting point
            • Wow thanks for that solution! Man this is an old thread, d_u_n. is my old username that was lost when the forums were upgraded. Well maybe not lost, could have been me being lazy and just making a new username.

              Very cool solution. I would say keeping your users and user data in phpBB is wise, as one of Modx's (few) weaknesses is handling robust user data.

              I have posted a tool to handle new posts and other new data dynamically, which might help you, but not sure because of the phpBB. The link is here: https://forums.modx.com/thread/91788/recent-posts-threads-for-discuss-by-rimotevst-kanev?page=2#dis-post-523019

              Also the Discuss subforum could be useful for you.

              Thanks again! Glad I still had a subscription to this thread!