You are here

function commerce_file_access in Commerce File 7.2

Determines if a user may perform the given operation on the licensed file.

A file is licensed if the user has a license for the parent product.

Note: When checking "view" access for all files of a product, it's more performant to simply check whether commerce_file_get_product_license() returned a license.

Parameters

$op: The operation to be performed on the licensed file. Possible values are:

  • "view"
  • "download"

$file: The file entity.

$account: Optional, a user object representing the user for whom the operation is to be performed. Determines access for a user other than the current user.

Return value

TRUE if the file is not licensable, or the user has access. FALSE otherwise.

2 calls to commerce_file_access()
commerce_file_file_download in ./commerce_file.module
Implements hook_file_download().
commerce_file_file_entity_access in ./commerce_file.module
Implements hook_file_entity_access().
1 string reference to 'commerce_file_access'
commerce_file_menu_alter in ./commerce_file.module
Implements hook_menu_alter().

File

./commerce_file.module, line 254
Extends Commerce License with the ability to sell access to files.

Code

function commerce_file_access($op, $file, $account = NULL) {
  if (!$account) {
    $account = $GLOBALS['user'];
  }

  // Checkout complete account override for anonymous users.
  if (!empty($_SESSION['commerce_license_uid']) && empty($account->uid)) {
    $account = user_load($_SESSION['commerce_license_uid']);
  }

  // No need to check access.
  if (commerce_file_bypass_license_control($account)) {
    return TRUE;
  }

  // This file is not licensable.
  if (!commerce_file_is_licensable($file)) {
    return TRUE;
  }

  // Look for a valid license.
  $license = commerce_file_get_license($op, $file, $account);
  return !empty($license);
}