You are here

function _filefield_icon_path in FileField 6.3

Same name and namespace in other branches
  1. 5.2 filefield.module \_filefield_icon_path()
  2. 6.2 filefield.theme.inc \_filefield_icon_path()

Given a file object, create a URL to a matching icon.

Parameters

$file: A file object.

$theme: Optional. The theme to be used for the icon. Defaults to the value of the "filefield_icon_theme" variable.

Return value

A string to the icon as a local path, or FALSE if an appropriate icon could not be found.

1 call to _filefield_icon_path()
_filefield_icon_url in ./filefield.theme.inc
Given a file object, create a URL to a matching icon.

File

./filefield.theme.inc, line 63
Theme functions used for normal file output.

Code

function _filefield_icon_path($file, $theme = NULL) {
  if (!isset($theme)) {
    $theme = variable_get('filefield_icon_theme', 'default');
  }

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

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

  // 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 ($icon_path = _filefield_create_icon_path($category . '-x-generic', $theme)) {
        return $icon_path;
      }
    }
  }

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

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