This is something I once wrote for someone (think it was merk?), and kept it in a file, and finally got around to clean it up and wrap it in a function.
Very useful for some hacks, hope this helps at least some of you.
Here is the full function, along with some basic instructions:
PHP Code:
/***********************************************************************
* Parameters:
* 1. The name of the permission you want to check for.
* Alternatively, it can take an array of permissions.
* Defaults to 'canview'.
* 2. The user ID of the user you are checking permissions for.
* Defaults to -1 (i.e current viewer).
* 3. The separator for the list of forum ID's.
* Return:
* 1. If the first parameter is a string, the function will
* return the list of forum ID's.
* 2. If the first parameter is an array, the function will
* return an associative array of permission => forum ID's.
* Example usage:
* 1. get_allowed_forums();
* Will return the list of forums the current user can view:
* 1,5,6,8
* 2. get_allowed_forums(array('canview', 'canpostnew'), 2);
* Will return an array that contains two keys, canview and
* canpostnew, each referring to the list of forums user
* number 2 can access:
* Array
* (
* [canview] => 3,5,7,8
* [canpostnew] => 3,7
* )
**********************************************************************/
function get_allowed_forums ($checkfor = 'canview', $userid = -1, $separator = ',') {
global $permissions, $DB_site, $bbuserinfo, $enableaccess, $hideprivateforums;
// (This is a really really fast query since it only
// uses the index and not the actual table.)
$forums = $DB_site->query('SELECT forumid FROM forum');
while ($forum = $DB_site->fetch_array($forums)) {
if ($enableaccess and is_array($accesscache[$forum['forumid']])) {
if ($accesscache[$forum['forumid']]['accessmask'] == 1) {
$forumperms = $usergroupdefault;
} else {
$forumperms = $nopermissions;
}
} elseif (is_array($forumpermscache[$forum['forumid']])) {
$forumperms = $forumpermscache[$forum['forumid']];
} else {
$forumperms = $permissions;
}
if (is_array($checkfor)) {
foreach ($checkfor as $permname) {
if ((!$hideprivateforums and $permname == 'canview') or $forumperms[$permname]) {
if ($allowedforums[$permname]) {
$allowedforums[$permname] .= $separator;
}
$allowedforums[$permname] .= $forum['forumid'];
}
}
} else {
if ((!$hideprivateforums and $checkfor == 'canview') or $forumperms[$checkfor]) {
if ($allowedforums) {
$allowedforums .= $separator;
}
$allowedforums .= $forum['forumid'];
}
}
}
I've added the entire function to functions.php. I added it as the second-to-last function, above doshutdown.
I tried to use the function from global.php (the forums, not the admin). Right above the part of global.php that parses the css (headinclude), header, and footer.
I've tried $jjr512=get_allowed_forums();. I've tried $jjr512=get_allowed_forums('canview',-1,',');. I've tried a lot of things. But whenever I try to use the function, I get this error: "Warning: Bad arguments to implode() in /home/jjr512/public_html/testvb/admin/functions.php on line 2289" Now as I have it in my functions.php, Line 2289 is: