Browse Source

Less use of mimedetect

pull/609/head
willtp87 10 years ago
parent
commit
e5d2ad0f63
  1. 5
      includes/datastream.inc
  2. 175
      includes/mime_detect.inc
  3. 5
      includes/mime_type.autocomplete.inc
  4. 182
      includes/mimetype.utils.inc
  5. 9
      islandora.module

5
includes/datastream.inc

@ -441,8 +441,9 @@ function islandora_view_datastream_deliver_chunks(AbstractDatastream $datastream
* The URI of the file. * The URI of the file.
*/ */
function islandora_view_datastream_retrieve_file_uri(AbstractDatastream $datastream) { function islandora_view_datastream_retrieve_file_uri(AbstractDatastream $datastream) {
$mime_detect = new MimeDetect(); module_load_include('inc', 'islandora', 'includes/mimetype.utils');
$extension = $mime_detect->getExtension($datastream->mimetype);
$extension = islandora_get_extension_for_mimetype($datastream->mimetype);
$file_uri = 'temporary://chunk_' . $datastream->parent->id . '_' . $datastream->id . '_' . $datastream->createdDate->getTimestamp() . '.' . $extension; $file_uri = 'temporary://chunk_' . $datastream->parent->id . '_' . $datastream->id . '_' . $datastream->createdDate->getTimestamp() . '.' . $extension;
if (!file_exists($file_uri)) { if (!file_exists($file_uri)) {
$file = new stdClass(); $file = new stdClass();

175
includes/mime_detect.inc

@ -56,178 +56,6 @@ class MimeDetect {
* $this->get_extension('image/jpeg') will always return 'jpg'. * $this->get_extension('image/jpeg') will always return 'jpg'.
* *
*/ */
// Openoffice:
'odb' => 'application/vnd.oasis.opendocument.database',
'odc' => 'application/vnd.oasis.opendocument.chart',
'odf' => 'application/vnd.oasis.opendocument.formula',
'odg' => 'application/vnd.oasis.opendocument.graphics',
'odi' => 'application/vnd.oasis.opendocument.image',
'odm' => 'application/vnd.oasis.opendocument.text-master',
'odp' => 'application/vnd.oasis.opendocument.presentation',
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
'odt' => 'application/vnd.oasis.opendocument.text',
'otg' => 'application/vnd.oasis.opendocument.graphics-template',
'oth' => 'application/vnd.oasis.opendocument.text-web',
'otp' => 'application/vnd.oasis.opendocument.presentation-template',
'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template',
'ott' => 'application/vnd.oasis.opendocument.text-template',
// Staroffice:
'stc' => 'application/vnd.sun.xml.calc.template',
'std' => 'application/vnd.sun.xml.draw.template',
'sti' => 'application/vnd.sun.xml.impress.template',
'stw' => 'application/vnd.sun.xml.writer.template',
'sxc' => 'application/vnd.sun.xml.calc',
'sxd' => 'application/vnd.sun.xml.draw',
'sxg' => 'application/vnd.sun.xml.writer.global',
'sxi' => 'application/vnd.sun.xml.impress',
'sxm' => 'application/vnd.sun.xml.math',
'sxw' => 'application/vnd.sun.xml.writer',
// K-office:
'kil' => 'application/x-killustrator',
'kpt' => 'application/x-kpresenter',
'kpr' => 'application/x-kpresenter',
'ksp' => 'application/x-kspread',
'kwt' => 'application/x-kword',
'kwd' => 'application/x-kword',
// Ms office 97:
'doc' => 'application/msword',
'xls' => 'application/vnd.ms-excel',
'ppt' => 'application/vnd.ms-powerpoint',
// Office2007:
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'docm' => 'application/vnd.ms-word.document.macroEnabled.12',
'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
'dotm' => 'application/vnd.ms-word.template.macroEnabled.12',
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12',
'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12',
'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12',
'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12',
'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12',
// Wordperfect (who cares?):
'wpd' => 'application/wordperfect',
// Common and generic containers:
'pdf' => 'application/pdf',
'eps' => 'application/postscript',
'ps' => 'application/postscript',
'rtf' => 'text/rtf',
'rtx' => 'text/richtext',
'latex' => 'application/x-latex',
'tex' => 'application/x-tex',
'texi' => 'application/x-texinfo',
'texinfo' => 'application/x-texinfo',
// *ml:
'css' => 'text/css',
'htm' => 'text/html',
'html' => 'text/html',
'wbxml' => 'application/vnd.wap.wbxml',
'xht' => 'application/xhtml+xml',
'xhtml' => 'application/xhtml+xml',
'xsl' => 'text/xsl',
'xslt' => 'text/xsl',
'csv' => 'text/csv',
'tsv' => 'text/tab-separated-values',
'txt' => 'text/plain',
// images:
"bmp" => "image/bmp",
'dng' => 'image/x-adobe-dng',
"gif" => "image/gif",
"ief" => "image/ief",
"jpeg" => "image/jpeg",
"jpe" => "image/jpeg",
"jpg" => "image/jpeg",
"jp2" => "image/jp2",
"png" => "image/png",
"tiff" => "image/tiff",
"tif" => "image/tiff",
"djvu" => "image/vnd.djvu",
"djv" => "image/vnd.djvu",
"wbmp" => "image/vnd.wap.wbmp",
"ras" => "image/x-cmu-raster",
"pnm" => "image/x-portable-anymap",
"pbm" => "image/x-portable-bitmap",
"pgm" => "image/x-portable-graymap",
"ppm" => "image/x-portable-pixmap",
"rgb" => "image/x-rgb",
"xbm" => "image/x-xbitmap",
"xpm" => "image/x-xpixmap",
"xwd" => "image/x-windowdump",
// videos:
"mkv" => "video/x-matroska",
"mpeg" => "video/mpeg",
"mpe" => "video/mpeg",
"mpg" => "video/mpeg",
"m4v" => "video/mp4",
"mp4" => "video/mp4",
"ogv" => "video/ogg",
"qt" => "video/quicktime",
"mov" => "video/quicktime",
"mxu" => "video/vnd.mpegurl",
"avi" => "video/x-msvideo",
"movie" => "video/x-sgi-movie",
"flv" => "video/x-flv",
"swf" => "application/x-shockwave-flash",
// Audio:
"mp3" => "audio/mpeg",
"mp4a" => "audio/mp4",
"m4a" => "audio/mp4",
"oga" => "audio/ogg",
"ogg" => "audio/ogg",
"flac" => "audio/x-flac",
"wav" => "audio/vnd.wave",
// Chemical:
// MDL Molfile.
"mol" => "chemical/x-mdl-molfile",
// XYZ format.
"xyz" => "chemical/x-xyz",
// PDB.
"pdb" => "chemical/x-pdb",
// ChemDraw CDX.
'cdx' => 'chemical/x-cdx',
// ChemDraw 3D.
"c3d" => "chemical/x-chem3d",
// ChemDraw file.
"chm" => "chemical/x-chemdraw",
// Crystallographic Information File.
"cif" => "chemical/x-cif",
// Chemical Markup Language.
"cml" => "chemical/x-cml",
// GAMESS Input.
"inp" => "chemical/x-gamess-input",
// GAMESS Output.
"gam" => "chemical/x-gamess-output",
// Gaussian Cube.
"cub" => "chemical/x-gaussian-cube",
// Gaussian 98/03 Cartesian Input.
"gau" => "chemical/x-gaussian-input",
// JCAMP Spectroscopic Data Exchange Format.
"jdx" => "chemical/x-jcamp-dx",
// OpenDX Grid.
"dx" => "chemical/x-jcamp-dx",
// MOPAC Cartesian.
"mop" => "chemical/x-mopac-input",
// Compressed formats:
// (note: http://svn.cleancode.org/svn/email/trunk/mime.types)
"tgz" => "application/x-gzip",
"gz" => "application/x-gzip",
"tar" => "application/x-tar",
"gtar" => "application/x-gtar",
"zip" => "application/x-zip",
"dat" => "application/octet-stream",
// others:
'bin' => 'application/octet-stream',
// Web Archives:
"warc" => "application/warc",
"json" => "application/json",
); );
protected $protectedFileExtensions; protected $protectedFileExtensions;
protected $extensionExceptions = array( protected $extensionExceptions = array(
@ -243,7 +71,8 @@ class MimeDetect {
* Construtor. * Construtor.
*/ */
public function __construct() { public function __construct() {
module_load_include('inc', 'islandora', 'includes/mimetype.utils');
$this->protectedMimeTypes = islandora_mime_mapping();
// Populate the reverse shortlist: // Populate the reverse shortlist:
$this->protectedFileExtensions = array_flip($this->protectedMimeTypes); $this->protectedFileExtensions = array_flip($this->protectedMimeTypes);
$this->protectedFileExtensions += $this->extensionExceptions; $this->protectedFileExtensions += $this->extensionExceptions;

5
includes/mime_type.autocomplete.inc

@ -14,9 +14,8 @@
* The rendered JSON results. * The rendered JSON results.
*/ */
function islandora_mime_type_autocomplete($string) { function islandora_mime_type_autocomplete($string) {
module_load_include('inc', 'islandora', 'includes/mime_detect'); require_once DRUPAL_ROOT . "/includes/file.mimetypes.inc";
$mime_detect = new MimeDetect(); $mime_types = file_mimetype_mapping();
$mime_types = $mime_detect->getMimeTypes();
$output = array(); $output = array();
foreach ($mime_types as $mime_type) { foreach ($mime_types as $mime_type) {
if (preg_match("/{$string}/i", $mime_type) !== 0) { if (preg_match("/{$string}/i", $mime_type) !== 0) {

182
includes/mimetype.utils.inc

@ -88,3 +88,185 @@ function islandora_get_extensions_for_datastream(AbstractObject $object, $dsid)
} }
return array_unique($extensions); return array_unique($extensions);
} }
/**
* Retrieve custom Islandora mime mappings.
*
* Our mime needs are rather extreme and we need to modify/extend Drupal's map.
*/
function islandora_mime_mapping() {
return array(
// Openoffice:
'odb' => 'application/vnd.oasis.opendocument.database',
'odc' => 'application/vnd.oasis.opendocument.chart',
'odf' => 'application/vnd.oasis.opendocument.formula',
'odg' => 'application/vnd.oasis.opendocument.graphics',
'odi' => 'application/vnd.oasis.opendocument.image',
'odm' => 'application/vnd.oasis.opendocument.text-master',
'odp' => 'application/vnd.oasis.opendocument.presentation',
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
'odt' => 'application/vnd.oasis.opendocument.text',
'otg' => 'application/vnd.oasis.opendocument.graphics-template',
'oth' => 'application/vnd.oasis.opendocument.text-web',
'otp' => 'application/vnd.oasis.opendocument.presentation-template',
'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template',
'ott' => 'application/vnd.oasis.opendocument.text-template',
// Staroffice:
'stc' => 'application/vnd.sun.xml.calc.template',
'std' => 'application/vnd.sun.xml.draw.template',
'sti' => 'application/vnd.sun.xml.impress.template',
'stw' => 'application/vnd.sun.xml.writer.template',
'sxc' => 'application/vnd.sun.xml.calc',
'sxd' => 'application/vnd.sun.xml.draw',
'sxg' => 'application/vnd.sun.xml.writer.global',
'sxi' => 'application/vnd.sun.xml.impress',
'sxm' => 'application/vnd.sun.xml.math',
'sxw' => 'application/vnd.sun.xml.writer',
// K-office:
'kil' => 'application/x-killustrator',
'kpt' => 'application/x-kpresenter',
'kpr' => 'application/x-kpresenter',
'ksp' => 'application/x-kspread',
'kwt' => 'application/x-kword',
'kwd' => 'application/x-kword',
// Ms office 97:
'doc' => 'application/msword',
'xls' => 'application/vnd.ms-excel',
'ppt' => 'application/vnd.ms-powerpoint',
// Office2007:
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'docm' => 'application/vnd.ms-word.document.macroEnabled.12',
'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
'dotm' => 'application/vnd.ms-word.template.macroEnabled.12',
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12',
'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12',
'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12',
'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12',
'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12',
// Wordperfect (who cares?):
'wpd' => 'application/wordperfect',
// Common and generic containers:
'pdf' => 'application/pdf',
'eps' => 'application/postscript',
'ps' => 'application/postscript',
'rtf' => 'text/rtf',
'rtx' => 'text/richtext',
'latex' => 'application/x-latex',
'tex' => 'application/x-tex',
'texi' => 'application/x-texinfo',
'texinfo' => 'application/x-texinfo',
// *ml:
'css' => 'text/css',
'htm' => 'text/html',
'html' => 'text/html',
'wbxml' => 'application/vnd.wap.wbxml',
'xht' => 'application/xhtml+xml',
'xhtml' => 'application/xhtml+xml',
'xsl' => 'text/xsl',
'xslt' => 'text/xsl',
'csv' => 'text/csv',
'tsv' => 'text/tab-separated-values',
'txt' => 'text/plain',
// images:
"bmp" => "image/bmp",
'dng' => 'image/x-adobe-dng',
"gif" => "image/gif",
"ief" => "image/ief",
"jpeg" => "image/jpeg",
"jpe" => "image/jpeg",
"jpg" => "image/jpeg",
"jp2" => "image/jp2",
"png" => "image/png",
"tiff" => "image/tiff",
"tif" => "image/tiff",
"djvu" => "image/vnd.djvu",
"djv" => "image/vnd.djvu",
"wbmp" => "image/vnd.wap.wbmp",
"ras" => "image/x-cmu-raster",
"pnm" => "image/x-portable-anymap",
"pbm" => "image/x-portable-bitmap",
"pgm" => "image/x-portable-graymap",
"ppm" => "image/x-portable-pixmap",
"rgb" => "image/x-rgb",
"xbm" => "image/x-xbitmap",
"xpm" => "image/x-xpixmap",
"xwd" => "image/x-windowdump",
// videos:
"mkv" => "video/x-matroska",
"mpeg" => "video/mpeg",
"mpe" => "video/mpeg",
"mpg" => "video/mpeg",
"m4v" => "video/mp4",
"mp4" => "video/mp4",
"ogv" => "video/ogg",
"qt" => "video/quicktime",
"mov" => "video/quicktime",
"mxu" => "video/vnd.mpegurl",
"avi" => "video/x-msvideo",
"movie" => "video/x-sgi-movie",
"flv" => "video/x-flv",
"swf" => "application/x-shockwave-flash",
// Audio:
"mp3" => "audio/mpeg",
"mp4a" => "audio/mp4",
"m4a" => "audio/mp4",
"oga" => "audio/ogg",
"ogg" => "audio/ogg",
"flac" => "audio/x-flac",
"wav" => "audio/vnd.wave",
// Chemical:
// MDL Molfile.
"mol" => "chemical/x-mdl-molfile",
// XYZ format.
"xyz" => "chemical/x-xyz",
// PDB.
"pdb" => "chemical/x-pdb",
// ChemDraw CDX.
'cdx' => 'chemical/x-cdx',
// ChemDraw 3D.
"c3d" => "chemical/x-chem3d",
// ChemDraw file.
"chm" => "chemical/x-chemdraw",
// Crystallographic Information File.
"cif" => "chemical/x-cif",
// Chemical Markup Language.
"cml" => "chemical/x-cml",
// GAMESS Input.
"inp" => "chemical/x-gamess-input",
// GAMESS Output.
"gam" => "chemical/x-gamess-output",
// Gaussian Cube.
"cub" => "chemical/x-gaussian-cube",
// Gaussian 98/03 Cartesian Input.
"gau" => "chemical/x-gaussian-input",
// JCAMP Spectroscopic Data Exchange Format.
"jdx" => "chemical/x-jcamp-dx",
// OpenDX Grid.
"dx" => "chemical/x-jcamp-dx",
// MOPAC Cartesian.
"mop" => "chemical/x-mopac-input",
// Compressed formats:
// (note: http://svn.cleancode.org/svn/email/trunk/mime.types)
"tgz" => "application/x-gzip",
"gz" => "application/x-gzip",
"tar" => "application/x-tar",
"gtar" => "application/x-gtar",
"zip" => "application/x-zip",
"dat" => "application/octet-stream",
// others:
'bin' => 'application/octet-stream',
// Web Archives:
"warc" => "application/warc",
"json" => "application/json",
);
}

9
islandora.module

@ -1649,12 +1649,13 @@ function islandora_download_clip(AbstractObject $object) {
/** /**
* Implements hook_file_mimetype_mapping_alter(). * Implements hook_file_mimetype_mapping_alter().
* *
* Grab custom islandora mime type list * Grab custom Islandora mime type list
* and add any missing ext/mimes to the drupal mapping * and add any missing ext/mimes to the Drupal mapping
*/ */
function islandora_file_mimetype_mapping_alter(&$mapping) { function islandora_file_mimetype_mapping_alter(&$mapping) {
$mime_detect = new MimeDetect(); module_load_include('inc', 'islandora', 'includes/mimetype.utils');
$types = $mime_detect->getMimeTypes();
$types = islandora_mime_mapping();
$diff = array_diff_key($types, $mapping['extensions']); $diff = array_diff_key($types, $mapping['extensions']);
foreach ($diff as $ext => $mime) { foreach ($diff as $ext => $mime) {

Loading…
Cancel
Save