You are here

function _filefield_icon_path in FileField 5.2

Same name and namespace in other branches
  1. 6.3 filefield.theme.inc \_filefield_icon_path()
  2. 6.2 filefield.theme.inc \_filefield_icon_path()
1 call to _filefield_icon_path()
filefield_icon_url in ./filefield.module
Determine the most appropriate icon for the given file's mimetype.

File

./filefield.module, line 975
Defines a file field type.

Code

function _filefield_icon_path($file, $theme = 'protocons') {

  // If there's an icon matching the exact mimetype, go for it.
  $dashed_mime = strtr($file['filemime'], array(
    '/' => '-',
  ));
  if ($iconpath = _filefield_create_icon_path($dashed_mime, $theme)) {
    return $iconpath;
  }

  // For a couple of mimetypes, we can "manually" tell a generic icon.
  if ($generic_name = _filefield_generic_icon_map($file)) {
    if ($iconpath = _filefield_create_icon_path($generic_name, $theme)) {
      return $iconpath;
    }
  }

  // Use generic icons for each category that provides such icons.
  foreach (array(
    'audio',
    'image',
    'text',
    'video',
  ) as $category) {
    if (strpos($file['filemime'], $category . '/') === 0) {
      if ($iconpath = _filefield_create_icon_path($category . '-x-generic', $theme)) {
        return $iconpath;
      }
    }
  }

  // Try application-octet-stream as last fallback.
  if ($iconpath = _filefield_create_icon_path('application-octet-stream', $theme)) {
    return $iconpath;
  }

  // Sorry, no icon can be found...
  return FALSE;
}