You are here

function _homebox_user_access_view_homebox in Homebox 7.3

Same name and namespace in other branches
  1. 6.3 homebox.module \_homebox_user_access_view_homebox()
  2. 6.2 homebox.module \_homebox_user_access_view_homebox()
  3. 7.2 homebox.module \_homebox_user_access_view_homebox()

Helper function to check if the current user can view a given homebox page

Parameters

$page: A page object

2 calls to _homebox_user_access_view_homebox()
homebox_edit_access in ./homebox.module
Check that a request is logged-in, has access to view the homebox, and has a valid token. Use tokens from homebox_get_token().
_homebox_user_access_view_user_homebox in ./homebox.module
Helper function to check access permissions for user profile Homebox
1 string reference to '_homebox_user_access_view_homebox'
homebox_menu in ./homebox.module
Implements hook_menu().

File

./homebox.module, line 1543
Homebox main file, takes care of global functions settings constants, etc.

Code

function _homebox_user_access_view_homebox($page, $require_login = FALSE) {
  global $user;
  if ($require_login && !$user->uid) {
    return FALSE;
  }

  // Admin is always allowed
  if (user_access('administer site configuration') || user_access('administer homebox')) {
    return TRUE;
  }
  elseif (!$page->settings['enabled']) {
    return FALSE;
  }
  elseif ($page->settings['roles']) {

    // Iterate each role to look for a match
    foreach ($page->settings['roles'] as $role) {
      $rl = user_role_load_by_name($role);
      if (array_key_exists($rl->rid, $user->roles)) {
        return TRUE;
      }
    }

    // No matches on restricted role
    return FALSE;
  }
  else {

    // If here, no access
    return FALSE;
  }
}