function forum_access_access in Forum Access 5
Same name and namespace in other branches
- 8 includes/forum_access.common.inc \forum_access_access()
- 6 forum_access.module \forum_access_access()
- 7 forum_access.module \forum_access_access()
See if a given user has access to a forum.
$tid -- the tid of the forum $type -- view, update, delete or create $account -- the account to test for. If NULL use current user.
1 call to forum_access_access()
- forum_access_init in ./
forum_access.module - Implementation of hook_init().
File
- ./
forum_access.module, line 481 - forum_access.module
Code
function forum_access_access($tid, $type, $account = NULL) {
static $cache = array();
if (!$account) {
global $user;
$account = $user;
}
if (user_access('administer forums', $account)) {
return TRUE;
}
if (!isset($cache[$account->uid][$tid][$type])) {
$roles = _forum_access_get_roles($account);
$result = db_result(db_query("SELECT tid FROM {forum_access} WHERE rid IN (%s) AND grant_{$type} = 1 AND tid = %d", $roles, $tid));
if ($result) {
$cache[$account->uid][$tid][$type] = TRUE;
}
else {
// check our moderators too
$acl_id = db_result(db_query("SELECT acl_id from {acl} WHERE module = 'forum_access' AND name = '%d'", $tid));
$result = db_result(db_query("SELECT uid FROM {acl_user} WHERE acl_id = %d AND uid = %d", $acl_id, $account->uid));
if ($result) {
$cache[$account->uid][$tid][$type] = TRUE;
}
else {
$cache[$account->uid][$tid][$type] = FALSE;
}
}
}
return $cache[$account->uid][$tid][$type];
}