You are here

function spaces_access_feature in Spaces 7

Same name and namespace in other branches
  1. 6.3 spaces.module \spaces_access_feature()
  2. 7.3 spaces.module \spaces_access_feature()

Access check for a given feature in the current space.

Parameters

$op: The operation to test access for. Optional, defaults to 'view'.

$feature: Feature to test access against.

$account: User account to test access for.

$space: The space to check access against.

$reset: Reset the access static cache.

4 calls to spaces_access_feature()
spaces_access_feature_perms in ./spaces.module
Access callback for spaces, with extra permission checking.
spaces_dashboard_access in spaces_dashboard/spaces_dashboard.module
Menu access callback.
spaces_menu_access in ./spaces.module
Spaces menu access callback. Allows space types to manage access as related to their space workflow. See hook_menu_alter() for how menu access callbacks / arguments get passed.
spaces_plugin_access_spaces_feature::access in includes/spaces_plugin_access_spaces_feature.inc
Check access directly.
1 string reference to 'spaces_access_feature'
spaces_plugin_access_spaces_feature::get_access_callback in includes/spaces_plugin_access_spaces_feature.inc
Provide the access check as a callback.

File

./spaces.module, line 501

Code

function spaces_access_feature($op = 'view', $feature, $account = NULL, $space = NULL, $reset = FALSE) {
  static $cache;
  $space = isset($space) ? $space : spaces_get_space();
  $cid = $op . ':' . $feature . ':' . (isset($account) ? $account->uid : 'CURRENT_USER') . ':' . (!empty($space) ? "{$space->type}-{$space->id}" : "SITE_SPACE");
  if (!isset($cache) || $reset) {
    $cache = array();
  }
  if (!isset($cache[$cid])) {

    // Allow access to features that are not spaces-compatible.
    // Allow access to features in the admin section of the site so menu items
    // are available on pages like 'admin/structure/menu' and 'admin/structure/context'.
    $features = spaces_features();
    if (!isset($features[$feature]) || arg(0) === 'admin') {
      $cache[$cid] = TRUE;
    }
    elseif ($space) {
      $cache[$cid] = $space
        ->access_feature($op, $feature, $account);
    }
    else {
      $features = variable_get('spaces_features', array());
      $cache[$cid] = user_access('access content', $account) && !empty($features[$feature]);
    }
  }
  return $cache[$cid];
}