You are here

function freelinking_file_file_callback in Freelinking 6.3

Same name and namespace in other branches
  1. 7.3 plugins/freelinking_file.inc \freelinking_file_file_callback()
1 call to freelinking_file_file_callback()
freelinking_file_image_callback in plugins/freelinking_file.inc
1 string reference to 'freelinking_file_file_callback'
freelinking_file.inc in plugins/freelinking_file.inc

File

plugins/freelinking_file.inc, line 14

Code

function freelinking_file_file_callback($target, $plugin) {

  // Is relative path?
  $pos = strpos($target['dest'], '/');
  if ($pos === FALSE || $pos > 0) {
    if (isset($target['other']['file_path'])) {
      $path = $target['other']['file_path'];
    }
    else {
      $path = variable_get('freelinking_file_file_path', file_directory_path());
    }
    $path .= '/' . $target['dest'];
  }
  elseif ($pos == 0) {

    // scrape off the starting slash that marks this as an unmodified path from site root.
    $path = substr($target['dest'], 1);
  }
  $check_path = $path;
  if (!file_check_path($check_path)) {
    return array(
      'failover' => 'error',
      'message' => t('File Not Found'),
    );
  }
  $headers = module_invoke_all('file_download', $path);
  if (in_array(-1, $headers)) {
    return array(
      'failover' => 'error',
      'message' => t('File Not Found'),
    );
  }
  if ($target['text']) {
    $title = $target['text'];
  }
  else {
    $title = basename($path);
  }
  return array(
    check_plain($title),
    file_create_url($path),
  );
}