You are here

function forum_access_access in Forum Access 6

Same name and namespace in other branches
  1. 8 includes/forum_access.common.inc \forum_access_access()
  2. 5 forum_access.module \forum_access_access()
  3. 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 $administer_nodes_sees_everything -- pass FALSE to ignore the 'administer nodes' permission

Return: FALSE - access not granted 1 - access granted 2 - access granted for forum moderator

8 calls to forum_access_access()
forum_access_init in ./forum_access.module
Implementation of hook_init().
forum_access_preprocess_forums in ./forum_access.module
Implementation of $modulename_preprocess_$hook() for forums.
_forum_access_comment_form in ./forum_access.node.inc
Remove the in-line 'Post new comment' form, if the user does not have the 'create' permission (see below). (This needs forum_access_preprocess_box() to clean up afterwards.)
_forum_access_forum_access_callback in ./forum_access.module
Access callback for the 'forum' menu path.
_forum_access_forum_form in ./forum_access.admin.inc
Rewrite the forum administration page with our new access rules.

... See full list

File

./forum_access.module, line 525
forum_access.module

Code

function forum_access_access($tid, $type, $account = NULL, $administer_nodes_sees_everything = TRUE) {
  static $cache = array();
  if (!$account) {
    global $user;
    $account = $user;
  }
  if ($account->uid == 1 || $administer_nodes_sees_everything && user_access('administer nodes', $account) && array_search($type, array(
    'view',
    'update',
    'delete',
  )) !== FALSE) {
    return 1;
  }
  if (!isset($cache[$account->uid][$tid][$type])) {
    if (!user_access('access content', $account)) {
      return $cache[$account->uid][$tid][$type] = FALSE;
    }
    $roles = array_keys($account->roles);
    $result = db_result(db_query("SELECT tid FROM {forum_access} WHERE rid IN (" . db_placeholders($roles) . ") AND grant_" . $type . " = 1 AND tid = %d", array_merge($roles, array(
      $tid,
    ))));
    if ($result) {
      $cache[$account->uid][$tid][$type] = 1;
    }
    else {

      // check our moderators too
      $acl_id = acl_get_id_by_number('forum_access', $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] = 2;
      }
      else {
        $cache[$account->uid][$tid][$type] = FALSE;
      }
    }
  }
  return $cache[$account->uid][$tid][$type];
}