This guide will show you how to get a user's group in phpBB and pass it into the JavaScript file.
Why
Having the user's group ID accessible in the includes/js/arrowchat_core.js file will allow you to limit a user's features based on their group. For example, you could only allow premium members to use video chat or chat rooms.
I don't use phpBB
Basically your installation will be the exact same except for a few things. Most importantly, you'll need to change the MySQL statement to get the user's group.
Installation
Getting the group ID
Open the includes/integration.php file. Create a new function in the file with the code below. If you are not using phpBB, you'll need to edit the MySQL statement here to work with your own integration.
- Code: Select all
function get_group_id($userid)
{
global $db;
// Get the user's group ID
$result = $db->execute("
SELECT group_id
FROM " . TABLE_PREFIX . "user_group
WHERE user_id = '" . $db->escape_string($userid) . "'
AND user_pending != 1
");
if ($result AND $db->count_select() > 0)
{
// In phpBB, a user can be in multiple groups so we need an array
$group_ids = array();
// Process the results
while ($row = $db->fetch_array($result))
{
$group_ids[] = $row['group_id'];
}
return json_encode($group_ids);
}
else
{
// MySQL statement didn't find a group ID or was invalid. Return a 0
return 0;
}
}
Passing the variable into the JavaScript
Open up the external.php file. Now you need to find where the DJS file loads and starts spitting out the JavaScript variables. At the time of writing this, it is line 348 with the code:
- Code: Select all
$settings .= 'var T=0,';
Right after that code (on a new line) you can add the group ID variable to the settings.
- Code: Select all
$group_id = get_group_id($userid);
$settings .= 'u_group_id=' . $group_id . ',';
Using the group ID
Now we can use the group ID in the /includes/js/arrowchat_core.js file (use .dev.js for a readable format). You simply need to check the 'u_group_id' variable to see which group the user is in. For example:
Get the user's first group ID in the array:
- Code: Select all
alert(u_group_id[0]);
Check if the user is in group 5:
- Code: Select all
if (a.inArray('5', u_group_id) != -1)
alert('User in group');
else
alert('User not in group');
Hide video chat if user is in group 4:
- Code: Select all
if (a.inArray('4', u_group_id) != -1)
a(".arrowchat_video_chat").hide();