MyBB Community Forums

Full Version: List groupnames with access to browsed forum
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I want to add a feature to my forum which would be a collapsible list of usergroups that have access to the forum which I'm browsing.

For instance:
You enter forum "MyBB Community Forums › 1.8 Support › General Support" and you can browse topics, but also, somewhere around them you get to open a list with groupnames that also can browse this forum. 

It's good for some boards and lets users make sure wheter the forum they are browsing is exclusive to their usergroup. 
Kind of a security measure also - helps administrator to quickly check viewing permission.

Is there a way to add this feature easily without making a plugin, or should I make a plugin request?

Thanks for any replies,
Cheers
requires plugin. or you can manually add the information in forum description or at forum rules .. etc
@.m. but that could also be possible with PHP in templates right? A simple query to the database - I could base it off from management.php in admin/modules/forum. This is for the /admin/index.php?module=forum-management&fid=17#tab_permissions link which shows you usergroups permissions for selected forum.

If you think there is nothing more for me to get in this forum, then please move this thread to Plugin Requests.
^ I don't think such information can be grabbed easily by using php in templates.

--- topic moved to plugin requests ---
I see it this way:
User visits forum X - it has fid=X so link is http://mybbforum.com/forumdisplay.php?fid=X
In forumdisplay template you have PHP code that queries DB using that last part of URL "fid=X".
Using the fid=X it checks who can browse the forum and lists the groupnames in array - formatting is irrelevant here.
Problem is how should the query look like?

If I understood well, table forumpermissions consists of information about restrictions in access to the forum - if you have inherited/default access range to forum X, then your group id will not figure in that table for the fid=X, but if your permissions are custom or simply not inherited, then you will figure in the table for fid=X.
I only had a quick look at how mybb deals with permissions, so maybe I'll figure it out soon enough.

Is there any easier way to query which usergroups can browse a forum?
Querying only forumpermissions seems like an incomplete solution.

Any help in getting this done would be great.
It doesn't have to be a full plugin.
I need just the query part giving groupid/groupnames with permission to browse a forum.
Probably going to need a plugin for this as it's gonna require several queries and JOINs from what I can tell. Have a look at this function and this one to get an idea of how MyBB does this checking on its own. I'll look at it more tomorrow and see if I can help you with the query(ies).
I've managed to make the query that gets us all tha data we need. The only thing to do now is to use it in a plugin.

I'm querying for all usergroup names (title) from table usergroups, except for groups with canview=0 for fid=(X,Y,n) in table forumpermission. I also exclude groups 5 (Awaiting Activation),7 (Banned), because they shouldn't be able to browse anything more then a guest, so they are irrelevant.

MySQL query looks like so:
SELECT title FROM mybb_usergroups 
WHERE gid NOT IN (
SELECT gid FROM mybb_forumpermissions
WHERE canview=0 AND fid IN(X,Y,Z,n)
) 
AND gid NOT IN(5,7)

The above query DOES consider inheriting and is a complete solution.

I think the plugin should:

1. Modify the forumdisplay template
- add {$canbrowseforum} (custom plugin variable holding the canbrowseforum template content) between {$header} and {$threadslist}
2. Add canbrowseforum template - global or additional template for each style 
- this would include how the output array would be formatted like
3. Check usergroup permissions for the browsed forum using $foruminfo['parentlist'] variable values so something like this:

$query = $db->query("SELECT title FROM mybb_usergroups 
WHERE gid NOT IN (
SELECT gid FROM mybb_forumpermissions
WHERE canview=0 AND fid IN(".$foruminfo['parentlist'].")
) 
AND gid NOT IN(5,7)");

4. Print out the results in {$canbrowseforum} template accordingly.


Update:

For now I've made a basic modification to forumdisplay.php file in the main mybb folder and in forumdisplay template. It looks ugly, but it's just the first version. 

1. In forumdisplay.php find these last lines of the file:

eval("\$forums = \"".$templates->get("forumdisplay")."\";");
output_page($forums);

2. Insert this before them:

//List all usergroups with permission to browse forum 

$groups_can_view_sql="
SELECT title FROM mybb_usergroups 
WHERE gid NOT IN(
SELECT gid FROM mybb_forumpermissions
WHERE canview=0 AND fid IN(".$foruminfo['parentlist'].")) 
AND gid NOT IN(5,7)"; 

$groups_can_view_result = $db->query($groups_can_view_sql);

while($row = mysql_fetch_assoc($groups_can_view_result)){
    $groups_can_view_array[] = $row;
}

$usergroup_titles = array_map('array_pop', $groups_can_view_array);
$groups_can_view = implode(',<br />', $usergroup_titles);

// End of groups_can_view feature

3. Upload that and overwrite the file. 
4. Open up forumdisplay template and find:
{$header}
{$moderatedby}

5. Change it to:
{$header}
<div style="border:2px solid black; background-color:grey; color:white; font-weight:bold;font-size:14px;">
<div style="text-align:center;">Usergroups with access to this forum:</div>
{$groups_can_view}
</div>
{$moderatedby}

The result:
[Image: C7Lo3Pe.png]


Soon enough I will make a nicer looking version will collapsing and in the future, hopefully, a plugin.