function tmgmt_file_file_download in Translation Management Tool 7
Same name and namespace in other branches
- 8 translators/tmgmt_file/tmgmt_file.module \tmgmt_file_file_download()
Implements hook_file_download().
File
- translators/
file/ tmgmt_file.module, line 162 - Module file of the translation management test module.
Code
function tmgmt_file_file_download($uri) {
// Get the file record based on the URI. If not in the database just return.
$files = file_load_multiple(array(), array(
'uri' => $uri,
));
if (count($files)) {
foreach ($files as $item) {
// Since some database servers sometimes use a case-insensitive comparison
// by default, double check that the filename is an exact match.
if ($item->uri === $uri) {
$file = $item;
break;
}
}
}
if (!isset($file)) {
return;
}
// Check if this file belongs to a job.
$usage_list = file_usage_list($file);
if (!isset($usage_list['tmgmt_file']['tmgmt_job'])) {
return;
}
foreach (tmgmt_job_load_multiple(array_keys($usage_list['tmgmt_file']['tmgmt_job'])) as $job) {
if (tmgmt_job_access('view', $job)) {
// Access is granted.
$headers = file_get_content_headers($file);
return $headers;
}
}
// Returning nothing means access denied unless another module specifically
// grants access.
}