You are here

function download_file_format_extension in DownloadFile 7

Same name and namespace in other branches
  1. 6 download_file.module \download_file_format_extension()
  2. 7.3 download_file.module \download_file_format_extension()
  3. 7.2 download_file.module \download_file_format_extension()

Get the acronym of file extension.

Parameters

$file: The file.

Return value

An array containing the formatted acronym of file extension.

1 call to download_file_format_extension()
theme_download_file_detail_accessible in ./download_file.formatter.inc
Theme function for the link accessible.

File

./download_file.module, line 280
Module to direct download files or images.

Code

function download_file_format_extension($file) {
  $extension = pathinfo(strtoupper(check_plain($file->filename)), PATHINFO_EXTENSION);
  switch ($file->filemime) {

    // Word document types.
    case 'application/msword':
    case 'application/doc':
    case 'application/vnd.ms-word':
    case 'application/winword':
    case 'application/word':
    case 'application/vnd.ms-word.document.macroEnabled.12':
    case 'application/vnd.oasis.opendocument.text':
    case 'application/vnd.oasis.opendocument.text-template':
    case 'application/vnd.oasis.opendocument.text-master':
    case 'application/vnd.oasis.opendocument.text-web':
    case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
    case 'application/vnd.wordperfect':
      return array(
        'definition' => 'DOCument',
        'name' => 'DOC',
      );

    // Spreadsheet document types.
    case 'application/vnd.ms-excel':
    case 'application/xls':
    case 'application/msexcel':
    case 'application/vnd.ms-excel.sheet.macroEnabled.12':
    case 'application/vnd.oasis.opendocument.spreadsheet':
    case 'application/vnd.oasis.opendocument.spreadsheet-template':
    case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
      return array(
        'definition' => 'eXceL Spreadsheet',
        'name' => 'XLS',
      );

    // Presentation document types.
    case 'application/vnd.ms-powerpoint':
    case 'application/powerpoint':
    case 'application/mspowerpoint':
    case 'application/ms-powerpoint':
    case 'application/vnd.ms-powerpoint.presentation.macroEnabled.12':
    case 'application/vnd.oasis.opendocument.presentation':
    case 'application/vnd.oasis.opendocument.presentation-template':
    case 'application/vnd.openxmlformats-officedocument.presentationml.presentation':
      return array(
        'definition' => 'PowerPoinT',
        'name' => 'PPT',
      );

    // Portable document types.
    case 'application/pdf':
    case 'application/x-pdf':
    case 'application/x-bzpdf':
    case 'application/x-gzpdf':
    case 'applications/vnd.pdf':
    case 'text/pdf':
    case 'text/x-pdf':
      return array(
        'definition' => 'Portable Document Format',
        'name' => 'PDF',
      );

    // ZIP compressed archive types.
    case 'application/zip':
    case 'application/gzip':
    case 'application/gzip-compressed':
    case 'application/x-zip':
    case 'application/x-zip-compressed':
    case 'application/x-bzip':
    case 'application/x-compress':
    case 'application/x-compressed':
    case 'application/x-gzip':
    case 'application/x-tgz':
      return array(
        'definition' => 'Archive',
        'name' => 'ZIP',
      );

    // RAR compressed archive types.
    case 'application/tar':
    case 'application/x-rar':
    case 'application/x-bzip-compressed-tar':
    case 'application/x-tar':
    case 'application/x-gtar':
    case 'application/x-tarz':
      return array(
        'definition' => 'Roshal ARchive',
        'name' => 'RAR',
      );

    // 7z compressed archive types.
    case 'application/x-7z-compressed':
      return array(
        'definition' => '7-Zip Archive',
        'name' => '7Z',
      );

    // Text file types.
    case 'application/txt':
    case 'text/plain':
      return array(
        'definition' => 'TeXTe',
        'name' => 'TXT',
      );

    // CSV aliases.
    case 'application/csv':
    case 'text/csv':
    case 'text/comma-separated-values':
      return array(
        'definition' => 'Comma-Separated Values',
        'name' => 'CSV',
      );

    // HTML aliases.
    case 'application/xhtml+xml':
    case 'text/html':
      return array(
        'definition' => 'HyperText Markup Language',
        'name' => 'HTML',
      );

    // XML aliases.
    case 'application/xml':
    case 'text/xml':
      return array(
        'definition' => 'eXtensible Markup Language',
        'name' => 'XML',
      );

    // RSS aliases.
    case 'application/rss+xml':
      return array(
        'definition' => 'Really Simple Syndication',
        'name' => 'RSS',
      );

    // JPEG images.
    case 'image/jpeg':
    case 'image/jpg':
      return array(
        'definition' => 'Joint Photographic Experts Group',
        'name' => 'JPEG',
      );

    // PNG images.
    case 'application/png':
    case 'image/png':
      return array(
        'definition' => 'Portable Network Graphics',
        'name' => 'PNG',
      );

    // GIF images.
    case 'image/gif':
      return array(
        'definition' => 'Graphics Interchange Format',
        'name' => 'GIF',
      );

    // Executable types.
    case 'application/exe':
    case 'application/dos-exe':
    case 'application/x-macbinary':
    case 'application/x-ms-dos-executable':
    case 'application/x-pef-executable':
      return array(
        'definition' => 'Executable',
        'name' => 'EXE',
      );

    // Audio Video Interleave types.
    case 'video/vnd.avi':
    case 'video/avi':
    case 'video/msvideo':
    case 'video/x-msvideo':
      return array(
        'definition' => 'Audio Video Interleave',
        'name' => 'AVI',
      );

    // FLash Video types.
    case 'video/x-flv':
    case 'video/mp4':
    case 'video/x-m4v':
      return array(
        'definition' => 'FLash Video',
        'name' => 'FLV',
      );

    // QuickTime movie types.
    case 'video/quicktime':
    case 'video/x-quicktime':
      return array(
        'definition' => 'QuickTime MOVie',
        'name' => 'MOV',
      );

    // Windows audio types.
    case 'audio/vnd.wave':
    case 'audio/wav':
    case 'audio/wave':
    case 'audio/x-wav':
      return array(
        'definition' => 'WAVeform Audio File Format',
        'name' => 'WAV',
      );

    // MPEG audio types.
    case 'audio/mpeg':
    case 'audio/x-mpeg':
    case 'audio/mp3':
    case 'audio/x-mp3':
    case 'audio/mpeg3':
    case 'audio/x-mpeg3':
    case 'audio/MPA':
    case 'audio/mpa-robust':
      return array(
        'definition' => 'MPEG-1 Audio Layer 3',
        'name' => 'MP3',
      );
    default:
      return $extension;
  }
}