You are here

function attachment_links_retrieve in Attachment Links 6

Same name and namespace in other branches
  1. 7 attachment_links.module \attachment_links_retrieve()

Fetch the reqested file for the given node.

Parameters

$node The node the file is attached to.:

$type The type of file requested: authoritative, newest, etc.:

Return value

Nothing if the download was successful. Otherwise, return a 404 error page if the node type doesn't have attachment links enabled or if the file could not be found.

1 string reference to 'attachment_links_retrieve'
attachment_links_menu in ./attachment_links.module
Implementation of hook_menu().

File

./attachment_links.module, line 185
The Attachment Links module provides permanent links to files attached to a node. A single, easy-to-remember URL can be used to retrieve the preferred (canonical) or newest version of a file regardless of how many versions of that file have been…

Code

function attachment_links_retrieve($node, $type) {

  // Check if this node type has attachment links enabled. If not, return a 404.
  if (!variable_get('attachment_links_' . $node->type, 0)) {
    return drupal_not_found();
  }
  switch ($type) {
    case 'newest':
      $query = "SELECT `filepath` FROM {files} f\n               INNER JOIN {upload} u ON f.`fid` = u.`fid`\n               WHERE u.`vid` = %d\n               ORDER BY f.`timestamp` DESC";
      break;
    case 'authoritative':
    default:
      $query = "SELECT `filepath` FROM {files} f\n\t             INNER JOIN {upload} u ON f.`fid` = u.`fid`\n\t             WHERE u.`vid` = %d\n\t             ORDER BY u.`weight` ASC";
      break;
  }
  $path = db_result(db_query($query, array(
    $node->vid,
  )));
  _attachment_links_download($path);
}