Assuming that your Joomla and Q2A installations are on the same server and under the same domain, the integration is actually very easy, once you've understood how to link into Joomla.
Start by following the standard integration instructions here: http://www.question2answer.org/single-sign-on.php.
For point 7, the correct data type to set here is "INT".
When you get to the final point (point 11), these are the code changes you will need to make in your qa-external-users.php file:
1. Several of the functions you have to change will need to access Joomla, and the code is similar, so write a single function for them all to share. I put it at the end of the qa-external-users.php file:
function qa_get_joomla_app() {
if(!defined('_JEXEC')) {
define( '_JEXEC', 1 );
$joomlaPath = "/var/www/myJoomlaSite/";
define('JPATH_BASE', $joomlaPath);
require_once( JPATH_BASE.'/includes/defines.php' );
require_once( JPATH_BASE.'/includes/framework.php' );
// Instantiate the application.
$app = JFactory::getApplication('site');
// Initialise the application.
$app->initialise();
}
}
The only line you need to change in the function above is the one setting the path. Change it to suit your Joomla installation.
2. qa_get_login_links(). This function sets where the login, logout and register links should point to. This will vary according to your Joomla site's setup, so adjust as necessary. But note that Joomla doesn't have a logout page as standard (it posts to a form instead, which won't work for this). To resolve this, I installed a Joomla plugin called Quick Logout, which allowed me to set up a logout.html URL that I could then reference from this Q2A function.
3.qa_get_logged_in_user(). This function needs to call your qa_get_joomla_app() function (see 1 above). Your code should look something like this:
function qa_get_logged_in_user()
{
qa_get_joomla_app();
$user = JFactory::getUser();
if($user) {
if($user->guest || $user->block) { return null; }
$level = QA_USER_LEVEL_APPROVED;
if($user->authorise('core.edit')) {$level = QA_USER_LEVEL_EDITOR;}
if($user->authorise('core.edit.state')) {$level = QA_USER_LEVEL_MODERATOR;}
if($user->authorise('core.manage')) {$level = QA_USER_LEVEL_ADMIN;}
if($user->authorise('core.admin') || $user->get('isRoot')) {$level = QA_USER_LEVEL_SUPER;}
return [
'userid' => $user->id,
'publicusername' => $user->username,
'email' => $user->email,
'level' => $level,
];
}
return null;
}
Note that I've used core Joomla permissions to map to Q2A access levels. If you want to use different permissions, then you may change the code above as applicable.
4. qa_get_user_email(). This should like this:
{
qa_get_joomla_app();
$user = JFactory::getUser();
if($user) {
return $user->email;
}
return null;
}
5. qa_get_userids_from_public(). This should look like this:
{
$output = [];
if(count($publicusernames)) {
qa_get_joomla_app();
foreach($publicusernames as $username) {
$output[$username] = JUserHelper::getUserId($username);
}
}
return $output;
}
6. qa_get_public_from_userids(). And this one should look like this:
{
$output = [];
if(count($userids)) {
qa_get_joomla_app();
foreach($userids as $userID) {
$output[$userID] = JFactory::getUser($userID)->username;
}
}
return $output;
}
7. Add a menu item in Joomla that links to your Q2A installation.
And that's it. That's all there is to do. You should now be able to log into Joomla, click the link to go to your Q+A board, and you will be logged in there as well.
So what else is there left to do?
Obviously theming; you'll want to style Q2A so it looks like it's part of your Joomla site.
And searching. As things stand, Joomla's and Q2A's search functionality are not integrated. When you're on a Joomla page, a search will give you results from Joomla's database. When you're on Q2A, searching will give you results from your Q+A board. I haven't investigated fully how to integrate these in more detail, but what I've found so far makes it seem like it might be quite tricky.