I made the following modification to the ATTACHMENT.MODULE
// $Id: attachment.module,v 1.7.2.1 2005/10/28 21:38:23 ccourtne Exp $

I added some code to append an image icon at the beginning of the linked item. If you put icons in a folder called "images", and name the files "***_icon.gif", the correct GIF will appear depending on the file extension. If you don't have a gif for a certain extension, nothing will appear (it seems, at least in firefox). So put in icons named "pdf_icon.gif" "doc_icon.gif" etc. into the folder images.

The entire function is pasted below, but I only changed the line:
$text = empty($attachment['title']) ? ('<img src="/images/' . (substr($attachment['filename'],-3)) . '_icon.gif"> ' . $attachment['filename']) : ('<img src="/images/' . (substr($attachment['filename'],-3)) . '_icon.gif"> ' . $attachment['title'] . ' (' . $attachment['filename'] . ')');

Hope this is useful to folks. I'm VERY new at Drupal, so if the experts out there have a more "drupal-ized" general modification that isn't so hard-coded, please feel free to contribute.

can view: http://www.livablestreets.info to see implementation.

Jeff

/**
 * Formats a list of attachments for a given node.
 */
function theme_attachments($node) {

  $output  = "<div class=\"attachments\">\n";

  $attributes['class'] = 'attachment-list';

  $header[0]['data'] = t('Filename/Title');
  $header[0]['class'] = 'filename';
  $header[1]['data'] = t('Size');
  $header[1]['class'] = 'size';

  foreach ((array)$node->attachments as $attachment) {
    if (!$attachment['hidden'] && !$attachment['deleted']) {
      $text = empty($attachment['title']) ? ('<img src="/images/' . (substr($attachment['filename'],-3)) . '_icon.gif"> ' . $attachment['filename']) : ('<img src="/images/' . (substr($attachment['filename'],-3)) . '_icon.gif"> ' . $attachment['title'] . ' (' . $attachment['filename'] . ')');
      $attrib = empty($attachment['description']) ? array() : array('title' => $attachment['description']);
      $row[0]['data'] = l($text, module_invoke('filemanager', 'url', $attachment['fid']), $attrib);
      $row[0]['data'] = module_invoke('filemanager', 'l', $text, $attachment['fid'], FALSE, $attrib, TRUE);
      $row[0]['class'] = 'filename';
      $row[1]['data'] = format_size($attachment['size']);
      $row[1]['class'] = 'size';
      $rows[] = $row;
    }
  }
  if (count($rows) > 0) {
    $output .= theme('table', $header, $rows, $attributes);
  }

  $output .= "</div>\n";

  return $output;
}
CommentFileSizeAuthor
#3 icons.zip9.43 KBrosenblum68
#2 attachment.module_icon.patch1.45 KBdrewish

Comments

drewish’s picture

do you have any icons you'd like to contribute?

drewish’s picture

StatusFileSize
new1.45 KB

I've been thinking about this and I really like the idea. What I'm still trying to figure out is the best implementation. I rolled a patch based on your suggested changes. I used more intermediate variables to make it clearer what was happening. That and I add an img element if the file exists.

rosenblum68’s picture

StatusFileSize
new9.43 KB

Attached zip file with a few icons:
PDF
DOC
XLS
PPT
TXT
IMG
HTM

drewish’s picture

Humm, it just occured to me, that we need to consider the copyright of the images. Those all look like they'd be copyrighted. Are there any GPL-able images we could use? Or, I suppose we could just distribute some generic ones and let people customize them if they wanted.

eaton’s picture

http://tango-project.org/Tango_Desktop_Project is a good place to look. They've got icons for a variety of files types, and they're designed specifically for OSS projects.

drewish’s picture

The "Standard MIME Type Icons" shown on in the gallery look promising...

ccourtne’s picture

Status: Active » Closed (won't fix)

Since the function that is getting modified is already a theme function I think this is best left in themes.