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.
https://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 11 years, 3 months ago.]