You are here

function pay::access in Pay 6

Same name and namespace in other branches
  1. 7 includes/handlers/pay.inc \pay::access()

File

includes/handlers/pay.inc, line 346
The base class for the Payment API.

Class

pay
@file The base class for the Payment API.

Code

function access($activity, $account = NULL) {
  if (!$account) {
    global $user;
    $account = $user;
  }

  // In the absence of any permissions, default access to TRUE.
  if (!is_array($this->permissions)) {
    return TRUE;
  }
  if (is_array($this->permissions) && ($perm = $this->permissions[$activity])) {
    foreach ($perm as $key => $status) {
      if (!$status) {
        continue;
      }

      // The owner of this item.
      if ($key == 'owner' && $this->uid) {
        if ($account->uid == $this->uid) {
          return TRUE;
        }
      }

      // The 'Everyone' permission.
      if ($key == 'all') {
        return TRUE;
      }

      // Any user with a named permission.
      if (substr($key, 0, 11) == 'permission:') {
        if (user_access(substr($key, 11), $account)) {
          return TRUE;
        }
      }

      // Any user with the defined role.
      if (substr($key, 0, 5) == 'role:') {
        if (isset($account->roles[substr($key, 5)])) {
          return TRUE;
        }
      }
    }
  }

  // If none of the above code returned TRUE, return false by default.
  return FALSE;
}