Commit 38fde101 authored by quicksketch's avatar quicksketch

#452634: Add ability to use alternative icon sets.

parent 51d42c67
......@@ -477,6 +477,18 @@ function filefield_icon_url($file) {
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(
'default' => drupal_get_path('module', 'filefield') . '/icons',
);
}
/**
* Access callback for the JavaScript upload and deletion AHAH callbacks.
*
......
......@@ -43,8 +43,8 @@ function theme_filefield_icon($file) {
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;
}
......@@ -63,41 +63,60 @@ function _filefield_icon_url($file, $theme = NULL) {
*/
function _filefield_icon_path($file, $theme = NULL) {
if (!isset($theme)) {
$theme = variable_get('filefield_icon_theme', 'protocons');
$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 ($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 = 'default';
}
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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment