theme_file_link

Versions
7
theme_file_link($variables)

Output a link to a file.

Parameters

$variables An associative array containing:

  • file: A file object to which the link will be created.

Code

modules/file/file.module, line 627

<?php
function theme_file_link($variables) {
  $file = $variables['file'];

  $url = file_create_url($file->uri);
  $icon = theme('file_icon', array('file' => $file));

  // Set options as per anchor format described at
  // http://microformats.org/wiki/file-format-examples
  $options = array(
    'attributes' => array(
      'type' => $file->filemime . '; length=' . $file->filesize,
    ),
  );

  // Use the description as the link text if available.
  if (empty($file->description)) {
    $link_text = check_plain($file->filename);
  }
  else {
    $link_text = check_plain($file->description);
    $options['attributes']['title'] = check_plain($file->filename);
  }

  return '<span class="file">' . $icon . ' ' . l($link_text, $url, $options) . '</span>';
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.