Index: filefield.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/filefield/filefield.module,v retrieving revision 1.223 diff -u -r1.223 filefield.module --- filefield.module 29 Jun 2010 21:28:55 -0000 1.223 +++ filefield.module 30 Jun 2010 01:33:53 -0000 @@ -477,6 +477,18 @@ return _filefield_icon_url($file); } + +/** + * Implementation of hook_filefield_icon_sets(). + * + * Define a list of icon sets and directories that contain the icons. + */ +function filefield_filefield_icon_sets() { + return array( + 'protocons' => drupal_get_path('module', 'filefield') . '/icons', + ); +} + /** * Access callback for the JavaScript upload and deletion AHAH callbacks. * Index: filefield.theme.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/filefield/filefield.theme.inc,v retrieving revision 1.11 diff -u -r1.11 filefield.theme.inc --- filefield.theme.inc 29 Jun 2010 23:49:11 -0000 1.11 +++ filefield.theme.inc 30 Jun 2010 01:33:53 -0000 @@ -43,8 +43,8 @@ function _filefield_icon_url($file, $theme = NULL) { global $base_url; - if ($iconpath = _filefield_icon_path($file, $theme)) { - return $base_url .'/'. $iconpath; + if ($icon_path = _filefield_icon_path($file, $theme)) { + return $base_url .'/'. $icon_path; } return FALSE; } @@ -68,36 +68,55 @@ // 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; + 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 ($iconpath = _filefield_create_icon_path($generic_name, $theme)) { - return $iconpath; + 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 ($iconpath = _filefield_create_icon_path($category .'-x-generic', $theme)) { - return $iconpath; + if ($icon_path = _filefield_create_icon_path($category .'-x-generic', $theme)) { + return $icon_path; } } } // Try application-octet-stream as last fallback. - if ($iconpath = _filefield_create_icon_path('application-octet-stream', $theme)) { - return $iconpath; + if ($icon_path = _filefield_create_icon_path('application-octet-stream', $theme)) { + return $icon_path; } // Sorry, no icon can be found... return FALSE; } -function _filefield_create_icon_path($iconname, $theme = 'protocons') { - $iconpath = drupal_get_path('module', 'filefield') - .'/icons/'. $theme .'/16x16/mimetypes/'. $iconname .'.png'; - if (file_exists($iconpath)) { - return $iconpath; +/** + * Internal function to convert a file icon theme name to a directory. + */ +function _filefield_icon_directory($theme = NULL) { + static $sets; + + if (!isset($sets)) { + $sets = module_invoke_all('filefield_icon_sets'); + drupal_alter('filefield_icon_sets', $sets); + } + + if (!isset($theme) || !isset($sets[$theme])) { + $theme = 'protocons'; + } + + return $sets[$theme]; +} + +function _filefield_create_icon_path($icon_name, $theme = NULL) { + $icons_directory = _filefield_icon_directory($theme); + $icon_path = $icons_directory .'/'. $icon_name .'.png'; + + if (file_exists($icon_path)) { + return $icon_path; } return FALSE; }