function freelinking_file_file_callback in Freelinking 7.3
Same name and namespace in other branches
- 6.3 plugins/freelinking_file.inc \freelinking_file_file_callback()
File plugin callback. Builds a link to a file.
Return value
array with link settings.
1 string reference to 'freelinking_file_file_callback'
- freelinking_file.inc in plugins/
freelinking_file.inc
File
- plugins/
freelinking_file.inc, line 21
Code
function freelinking_file_file_callback($target, $plugin) {
// Remove slash if it's present at first character
$path = preg_replace('/^\\//', '', $target['dest']);
if (isset($target['other']['file_path'])) {
$path = $target['other']['file_path'] . '/' . $path;
}
else {
$path = variable_get('freelinking_file_file_path', file_default_scheme() . '://') . $path;
}
if (!file_exists($path)) {
return array(
'failover' => 'error',
'message' => t('File @name not found', array(
'@name' => basename($path),
)),
);
}
// Check access permissions
$headers = module_invoke_all('file_download', $path);
if (in_array(-1, $headers)) {
return array(
'failover' => 'error',
'message' => t('File not found'),
);
}
// Build link
if ($target['text']) {
$title = $target['text'];
}
else {
$title = basename($path);
}
$url = file_create_url($path);
return array(
check_plain($title),
$url,
);
}