When editing a node and attaching files to the node through webfm the attached files display with appropriate icons. For example a PDF file will display a pdf icon.
However when viewing the node after saving the plane f.gif icon is assigned to all file types including PDF.

Question:
is this a setting I've done wrong?
How can I supply a new icon for a different file type? (example: *.lbxoeb files use lbxoeb.gif)?

Thanks for your input.

Comments

robmilne’s picture

You could do the following inside webfm.module:

/**
 * Displays file attachments in table
 */
function theme_webfm_attachments($files) {
  global $base_url;
  $header = array(t('Attachment'), t('Size'));
  $rows = array();
  foreach ($files as $file) {
    // 0 =inline : 1 = attach
    $icon_path = $base_url.'/'.variable_get('webfm_icon_dir', 'modules/webfm/image/icon').'/'._webfm_get_icon($file->e);
    $href = array('data' => l('<img src="'.$icon_path.'" alt="[file]" title="download as file"/>&nbsp;', 'webfm_send/'.$file->id.'/1', '', '' , '' , '', TRUE).l(check_plain($file->ftitle ? $file->ftitle : $file->n), 'webfm_send/'.$file->id));
    $rows[] = array($href, format_size($file->s));
  }
  if (count($rows)) {
    return theme('table', $header, $rows, array('id' => 'webfm-attach-list'));
  }
}

function _webfm_get_icon($ext) {
  // Try and find appropriate type
  switch(strtolower($ext)) {
    case 'image/gif':
    case 'image/png':
    case 'image/jpg':
    case 'image/jpeg':
    case 'image/bmp':
    case 'image/tiff':
      $icon = 'i.gif';
      break;
    case 'video/mpeg':
    case 'video/quicktime':
    case 'video/x-msvideo':
      $icon = 'avi.gif';
      break;
    case 'audio/mpeg':
      $icon = 'mp3.gif';
      break;
    case 'application/pdf':
      $icon = 'pdf.gif';
      break;
    case 'application/zip':
    case 'application/x-zip':
    case 'application/x-gzip':
      $icon = 'zip.gif';
      break;
    case 'application/msword':
      $icon = 'doc.gif';
      break;
    case 'application/vnd.ms-excel':
      $icon = 'xls.gif';
      break;
    case 'application/msword':
      $icon = 'doc.gif';
      break;
    default:
      $icon = 'f.gif';
      break;
  }
  return $icon;
}

The problem here is that you may not like the default icons, etc so you could point to another image folder inside /admin/settings/webfm that used that same file names for the gifs. I haven't made this a patch because I think there is probably a more portable and clean way of handling the icon substitutions.

robmilne’s picture

Status: Active » Fixed
Plecebo’s picture

I'm having this problem as well. In the WebFM interface I see the appropriate Icon e.g. pdf, word etc (on this page mysite/node/15/edit), but when i view the node normally (mysite/node/15) i only see the f.gif image, not the appropriate icon.

I looked in my webfm.module file and I have nearly exactly the same code as is listed above, the only difference being I have this code:

$rows[] = array(array('data' => $file->fdesc, 'colspan' => '2'));

everything else is identical.

Any Ideas?

robmilne’s picture

Argh! That line was provisional and shouldn't have made it to the release. You can remove it if you don't want to display the file description metadata on alternating table rows. I'll address the image issue for attachments when I next update the dev version.

peterpoe’s picture

I had the same problem with an mp3 file. I looked at the file metadata information, where the mime filetype was mp3, so I added the following lines to the _webfm_get_icon function:

case 'mp3':
  $icon = 'mp3.gif';
  break;

I also a noticed strange behavior with pdf files: the mime filetype listed is "application/x-filler". How's that?

robmilne’s picture

I'm not familiar with all the mime extensions and haven't come across "application/x-filler" before. That particular extension may be a result of how the file was uploaded.

The extension handling is a bit ad hoc and not high on my priorities for fixing but I will keep it in mind.

Anonymous’s picture

Status: Fixed » Closed (fixed)