You are here

function gallery_assist_file_download in Gallery Assist 6

Implementation of hook_file_download.

File

./gallery_assist.module, line 5508
Drupal content type with gallery functionality.

Code

function gallery_assist_file_download($filepath) {
  global $user;

  // Check the original preset because img, thm and prev are not listed in the files table.
  if (preg_match('/prev/', $filepath) || preg_match('/thm/', $filepath) || preg_match('/img/', $filepath)) {
    $filepath = preg_replace('/prev\\//', '', $filepath);
    $filepath = preg_replace('/thm\\//', '', $filepath);
    $filepath = preg_replace('/img\\//', '', $filepath);
  }

  // Return headers for images.
  $path = file_create_path($filepath);
  if (!($path && file_exists($path))) {
    return;
  }
  $q = "SELECT f.*, p.nid, n.type FROM {files} f JOIN {gallery_assist_item} p ON p.fid=f.fid JOIN {node} n ON n.nid=p.nid WHERE filepath='%s'";

  //$file = db_fetch_object(db_query(db_rewrite_sql($q), $filepath));
  if (!($file = db_fetch_object(db_query(db_rewrite_sql($q), $path)))) {
    return;
  }
  if ($user->uid == 1 || $user->uid == $file->uid || gallery_assist_check_access($node)) {
    return array(
      'Content-Type: ' . $file->filemime,
      'Content-Length: ' . (int) $file->filesize,
    );
  }
  else {
    return -1;
  }
}