You are here

function track_da_files_file_download_access_alter in Track da files 7

Implements hook_file_download_access_alter().

Calls counting function for private files displays.

File

./track_da_files.module, line 511
This file contains Track da files main functions.

Code

function track_da_files_file_download_access_alter(&$grants, $file, $entity_type) {

  // Retrieve entity id information in query parameters.
  if (isset($_GET['id'])) {
    $id = $_GET['id'];
  }
  if (isset($_GET['type'])) {
    $type = $_GET['type'];
  }
  global $user;
  $track = track_da_files_roles($user);

  // If role should be skipped, no counting.
  if (!$track) {
    return NULL;
  }
  elseif (!in_array(TRUE, $grants)) {
    return NULL;
  }
  elseif ($track && in_array(TRUE, $grants) && isset($_GET['file'])) {
    $uri = $file['uri'];
    $fid = $file['fid'];
    if (!empty($fid)) {
      if (!empty($id) && !empty($type)) {
        track_da_files_register_new_display($uri, $fid, $id, $type);
      }
      else {
        track_da_files_register_new_display($uri, $fid);
      }
    }
  }
}