You are here

function asset_file_download in Asset 5

File

./asset.module, line 992

Code

function asset_file_download($file) {
  global $user;
  $filename = basename($file);
  list($path) = split("/" . $filename, $file);
  $public = db_result(db_query("SELECT status FROM {asset} WHERE type='local' AND dirname='%s' AND filename='%s' LIMIT 1", $path, $filename));
  if ($public || $user->uid == 1) {
    $mime = function_exists(mime_content_type) ? mime_content_type($file) : "";
    return array(
      'Content-type:' . $mime,
    );
  }
  else {
    $aid = db_result(db_query("SELECT aid FROM {asset} WHERE type='local' AND dirname='%s' AND filename='%s' LIMIT 1", $path, $filename));
    $roles = db_query("SELECT rid, status FROM {asset_role} WHERE aid=%d", $aid);
    while ($role = db_fetch_object($roles)) {
      if ($role->status && $user->roles[$role->rid]) {
        $mime = function_exists(mime_content_type) ? mime_content_type($file) : "";
        return array(
          'Content-type:' . $mime,
        );
      }
    }
  }
}