Location: PHPKode > projects > Blandware AtLeap Lite - CMS on PHP > atleaplite/include/util/resource_types.php
<?php
/*
 *  Copyright 2008 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

/**
 * Resource types definitions.
 *
 * @package     AtleapLite
 * @author      Roman Puchkovskiy
 * @license     http://www.apache.org/licenses/LICENSE-2.0  Apache License, Version 2.0
 */

/**
 * Resource types
 */
$resourceTypes = array(
	'image' => array(
		'image/png' => array(
			'png'
		),
		'image/gif' => array(
			'gif'
		),
		'image/jpeg' => array(
			'jpg',
			'jpeg',
			'jpe',
			'jfif',
			'pjpeg',
			'pjp'
		)
	),
	'document' => array(
        'text/html' => array(
        	'html',
        	'htm'
        ),
        'application/xhtml+xml' => array(
        	'xhtml',
        	'xht'
        ),
        'text/xml' => array(
        	'xml'
        ),
        'text/plain' => array(
        	'txt'
        ),
        'application/msword' => array(
        	'doc'
        ),
        'application/rtf' => array(
        	'rtf'
        ),
        'application/vnd.ms-excel' => array(
        	'xls'
        ),
        'application/vnd.ms-powerpoint' => array(
        	'ppt'
        ),
        'application/pdf' => array(
        	'pdf'
        )
	),
	'file' => array(
        'audio/x-aiff' => array(
        	'aif',
        	'aifc',
        	'aiff'
        ),
        'application/x-aim' => array(
        	'aim'
        ),
        'application/astound' => array(
        	'asd'
        ),
        'application/x-asap' => array(
        	'asp'
        ),
        'image/x-jg' => array(
        	'art'
        ),
        'video/x-ms-asf' => array(
        	'asf',
        	'asx'
        ),
        'audio/basic' => array(
        	'au',
        	'snd',
        	'ulw'
        ),
        'video/x-msvideo' => array(
        	'avi'
        ),
        'video/x-rad-screenplay' => array(
        	'avx'
        ),
        'application/x-bcpio' => array(
        	'bcpio'
        ),
        'application/octet-stream' => array(
        	'exe',
        	'bin'
        ),
        'application/x-cdf' => array(
        	'cdf'
        ),
        'internal/cgi' => array(
        	'cgi'
        ),
        'application/x-fortezza-ckl' => array(
        	'ckl'
        ),
        'application/x-x509-ca-cert' => array(
        	'cer'
        ),
        
        'application/java' => array(
        	'class'
        ),
        'application/x-cpio' => array(
        	'cpio'
        ),
        'application/x-mscardfile' => array(
        	'crd'
        ),
        'application/x-pkcs7-crl' => array(
        	'crl'
        ),
        'application/x-csh' => array(
        	'csh'
        ),
        'text/css' => array(
        	'css'
        ),
        'application/msword' => array(
        	'dot',
        	'wiz'
        ),
        'video/x-dv' => array(
        	'dv'
        ),
        'drawing/x-dwf' => array(
        	'dwf'
        ),
        'image/vng' => array(
        	'dwg',
        	'svf'
        ),
		'image/bmp' => array(
			'bmp',
			'dib'
		),
        'dynamo-internal/template' => array(
        	'dyn'
        ),
        'dynamo-internal/dynjava' => array(
        	'dynjava'
        ),
        'application/x-dvi' => array(
        	'dvi'
        ),
        'text/x-setext' => array(
        	'etx'
        ),
        'application/pre-encrypted' => array(
        	'enc'
        ),
        'audio/echospeech' => array(
        	'es',
        	'esl'
        ),
        'application/x-earthtime' => array(
        	'etc'
        ),
        'application/x-envoy' => array(
        	'evy'
        ),
        'image/fif' => array(
        	'fif'
        ),
        'application/x-maker' => array(
        	'fm'
        ),
        'video/isivideo' => array(
        	'fvi'
        ),
        'application/x-gtar' => array(
        	'gtar'
        ),
        'application/x-gzip' => array(
        	'gz'
        ),
        'application/x-hdf' => array(
        	'hdf'
        ),
        'application/winhlp' => array(
        	'hlp'
        ),
        'application/mac-binhex40' => array(
        	'hqx'
        ),
        'text/x-component' => array(
        	'htc'
        ),
        'text/html' => array(
        	'body'
        ),
        'application/mac-binhex40' => array(
        	'hqx'
        ),
        'x-conference/x-cooltalk' => array(
        	'ice'
        ),
        'image/ief' => array(
        	'ief'
        ),
        'image/ifs' => array(
        	'ifs'
        ),
        'internal/php4' => array(
        	'php',
        	'inc'
        ),
        'application/x-NET-Install' => array(
        	'ins'
        ),
        'dynamo-internal/html' => array(
        	'jhtml',
        	'jhtm'
        ),
        'text/vnd.sun.j2me.app-descriptor' => array(
        	'jad'
        ),
        'application/java-archive' => array(
        	'jar'
        ),
        'text/plain' => array(
        	'java',
        	'jsf',
        	'jspf',
        	'dtd'
        ),
        'application/x-java-jnlp-file' => array(
        	'jnlp'
        ),
        'text/javascript' => array(
        	'js'
        ),
        'application/x-javascript-config' => array(
        	'jsc'
        ),
        'dynamo-internal/plain' => array(
        	'jtext',
        	'jtxt'
        ),
        'audio/x-midi' => array(
        	'kar'
        ),
        'application/x-latex' => array(
        	'latex'
        ),
        'audio/x-liveaudio' => array(
        	'lam'
        ),
        'application/fastman' => array(
        	'lcc'
        ),
        'application/x-msmediaview' => array(
        	'm13',
        	'm14'
        ),
        'audio/x-mpegurl' => array(
        	'm3u'
        ),
        'image/x-macpaint' => array(
        	'mac'
        ),
        'application/x-troff-man' => array(
        	'man'
        ),
        'dynamo-internal/map' => array(
        	'map'
        ),
        'application/mbedlet' => array(
        	'mbd'
        ),
        'application/x-msaccess' => array(
        	'mdb'
        ),
        'application/x-troff-me' => array(
        	'me'
        ),
        'audio/x-midi' => array(
        	'mid',
        	'midi'
        ),
        'application/x-mif' => array(
        	'mif',
        	'mi'
        ),
        'application/x-msmoney' => array(
        	'mny'
        ),
        'application/x-mocha' => array(
        	'moc',
        	'mocha'
        ),
        'video/quicktime' => array(
        	'mov',
        	'moov',
        	'qt'
        ),
        'video/x-sgi-movie' => array(
        	'movie'
        ),
     	'audio/x-mpeg' => array(
     		'mp3',
     		'mp1',
     		'mp2',
        	'abs',
     		'mpa',
     		'mpega'
     	),
     	'video/mpeg' => array(
     		'mpeg',
     		'mpe',
     		'mpegv',
     		'mpg',
     		'mpv'
     	),
     	'video/mpeg2' => array(
     		'mpv2'
     	),
        
        'application/x-wais-source' => array(
        	'ms'
        ),
        'application/x-netcdf' => array(
        	'nc'
        ),
        'application/oda' => array(
        	'oda'
        ),
        'audio/x-pac' => array(
        	'pac'
        ),
        'audio/x-epac' => array(
        	'pae'
        ),
        'image/x-photo-cd' => array(
        	'pcd'
        ),
        'image/x-portable-bitmap' => array(
        	'pbm'
        ),
        'image/x-portable-graymap' => array(
        	'pgm'
        ),
        'image/pict' => array(
        	'pict',
        	'pic',
        	'pct'
        ),
        'audio/x-scpls' => array(
        	'pls'
        ),
        'application/x-pl' => array(
        	'pl'
        ),
        'image/x-portable-anymap' => array(
        	'pnm'
        ),
        'image/x-macpaint' => array(
        	'pnt'
        ),
        'image/x-portable-pixmap' => array(
        	'ppm'
        ),
        
        'application/vnd.ms-powerpoint' => array(
        	'pps',
        	'pot'
        ),
        'application/x-ns-proxy-autoconfig' => array(
        	'proxy'
        ),
        'application/postscript' => array(
        	'ps',
        	'eps',
        	'ai'
        ),
        'image/x-photoshop' => array(
        	'psd'
        ),
        'application/x-mspublisher' => array(
        	'pub'
        ),
        'image/x-quicktime' => array(
        	'qti',
        	'qtif'
        ),
        'audio/x-pn-realaudio' => array(
        	'ra',
        	'ram'
        ),
        'image/x-cmu-raster' => array(
        	'ras'
        ),
        'image/x-rgb' => array(
        	'rgb'
        ),
        'application/vnd.rn-realmedia' => array(
        	'rm'
        ),
        'text/richtext' => array(
        	'rtx'
        ),
        'application/x-msschedule' => array(
        	'scd'
        ),
        'application/java-serialized-object' => array(
        	'ser'
        ),
        'application/x-sh' => array(
        	'sh'
        ),
        'application/x-shar' => array(
        	'shar'
        ),
        'audio/x-midi' => array(
        	'smf'
        ),
        'application/studiom' => array(
        	'smp'
        ),
        'application/astround' => array(
        	'sn'
        ),
        'application/x-sprite' => array(
        	'spr',
        	'sprite'
        ),
        'application/x-stuffit' => array(
        	'sit'
        ),
        'application/x-wais-source' => array(
        	'src'
        ),
        'application/x-sv4cpio' => array(
        	'sv4cpio'
        ),
        'application/x-sv4crc' => array(
        	'sv4crc'
        ),
        'application/x-shockwave-flash' => array(
        	'swf'
        ),
        'application/x-troff' => array(
        	't',
        	'roff',
        	'tr'
        ),
        'text/x-speech' => array(
        	'talk'
        ),
        'application/x-tar' => array(
        	'tar'
        ),
        'application/x-timbuktu' => array(
        	'tbp'
        ),
        'application/timbuktu' => array(
        	'tbt'
        ),
        'application/x-tcl' => array(
        	'tcl'
        ),
        'application/x-tex' => array(
        	'tex'
        ),
        'application/x-texinfo' => array(
        	'texi',
        	'texinfo'
        ),
        'image/tiff' => array(
        	'tif',
        	'tiff'
        ),
        'application/x-tkined' => array(
        	'tki',
        	'tkined'
        ),
        'text/tab-separated-values' => array(
        	'tsv'
        ),
        'application/x-msterminal' => array(
        	'trm'
        ),
        'video/vivo' => array(
        	'vivo',
        	'viv'
        ),
        'x-world/x-vrt' => array(
        	'vrt'
        ),
        'application/x-ustar' => array(
        	'ustar'
        ),
        'image/x-xbitmap' => array(
        	'xbm'
        ),
        'text/xml' => array(
        	'xsl'
        ),
        'application/vnd.ms-excel' => array(
        	'xla',
        	'xlc',
        	'xlm',
        	'xlt',
        	'xlw'
        ),
        'image/x-xpixmap' => array(
        	'xpm'
        ),
        'image/x-xwindowdump' => array(
        	'xwd'
        ),
        'audio/x-wav' => array(
        	'wav'
        ),
        'image/svg+xml' => array(
        	'svg',
        	'svgz'
        ),
        'application/x-visio' => array(
        	'vsd'
        ),
        'image/vnd.wap.wbmp' => array(
        	'wbmp'
        ),
        'application/x-msmetafile' => array(
        	'wmf'
        ),
        'video/wavelet' => array(
        	'wv'
        ),
        'text/vnd.wap.wml' => array(
        	'wml'
        ),
        'application/vnd.wap.wmlc' => array(
        	'wmlc'
        ),
        'text/vnd.wap.wmlscript' => array(
        	'wmls'
        ),
        'application/vnd.wap.wmlscriptc' => array(
        	'wmlscriptc'
        ),
        'x-world/x-vrml' => array(
        	'wrl'
        ),
        'application/x-compress' => array(
        	'z'
        ),
        'application/zip' => array(
        	'zip'
        ),
		'application/x-rar' => array(
			'rar'
		)
	)
);

/**
 * Mapping from extensions to MIME types
 */
$mimeTypes = array();
/**
 * Mapping from MIME types to resource types
 */
$mimeTypesToTypes = array();

foreach ($resourceTypes as $typeName => $resourceType) {
    foreach ($resourceType as $mimeType => $extensions) {
        foreach ($extensions as $extension) {
            if (isset($mimeTypes[$extension])) {
                echo "Error: $extension corresponds to more than one mime-type\n";
            } else {
                $mimeTypes[$extension] = $mimeType;
                switch ($typeName) {
                case 'file':
                    $numericType = RESOURCE_TYPE_FILE;
                    break;
                case 'image':
                    $numericType = RESOURCE_TYPE_IMAGE;
                    break;
                case 'document':
//                    $numericType = RESOURCE_TYPE_DOCUMENT;
                    // by now treating document as a file
                    $numericType = RESOURCE_TYPE_FILE;
                    break;
                }
                $mimeTypesToTypes[$mimeType] = $numericType;
            }
        }
    }
}

/**
 * Mapping from MIME types to icons
 */
$mimeTypesToIcons = array(
    'application/postscript'    => 'ai',
    'video/x-msvideo'           => 'avi',
    'image/bmp'                 => 'bmp',
    'application/msword'        => 'doc',
    'application/octet-stream'  => 'exe',
    'image/gif'                 => 'gif',
    'text/html'                 => 'html',
    'image/jpeg'                => 'jpg',
    'text/javascript'           => 'js',
    'application/x-msaccess'    => 'mdb',
    'audio/x-mpeg'              => 'mp3',
    'application/pdf'           => 'pdf',
    'image/png'                 => 'png',
    'application/vnd.ms-powerpoint' => 'ppt',
    'application/x-shockwave-flash' => 'swf',
    'text/plain'                => 'txt',
    'application/x-visio'       => 'vsd',
    'application/vnd.ms-excel'  => 'xls',
    'text/xml'                  => 'xml',
    'application/zip'           => 'zip'
);

/**
 * Detects MIME type by file name (actually, by its extension).
 *
 * @global array MIME types
 * @param string $name  file name
 * @return string|null MIME type or null if unknown
 */
function detectMimeType($name) {
    global $mimeTypes;

    $name = strtolower($name);
    $ext = strrchr($name, '.');
    if (empty($ext)) {
        return null;
    } else {
        $ext = substr($ext, 1);
        if (empty($ext)) {
            return null;
        } else {
            return $mimeTypes[$ext];
        }
    }
}

/**
 * Returns resource icon corresponding to its MIME type.
 *
 * @global array MIME types to icons mapping
 * @param string $name  file name
 * @return string|null resource icon name or null if not known
 */
function getResourceIconByMimeType($name) {
    global $mimeTypesToIcons;

    $mimeType = detectMimeType($name);
    if (empty($mimeType)) {
        return null;
    }
    return $mimeTypesToIcons[$mimeType];
}

/**
 * Detects resource type by its file name.
 *
 * @global array mapping from MIME types to resource types
 * @param string $name  file name
 * @return int resource type
 */
function getResourceType($name) {
    global $mimeTypesToTypes;

    $mimeType = detectMimeType($name);
    if (isset($mimeTypesToTypes[$mimeType])) {
        return $mimeTypesToTypes[$mimeType];
    } else {
        return RESOURCE_TYPE_FILE;
    }
}

/**
 * Detects whether resource is image.
 *
 * @param string $name  file name
 * @return bool true if resource is image
 */
function isResourceImage($name) {
    return getResourceType($name) == RESOURCE_TYPE_IMAGE;
}


?>
Return current item: Blandware AtLeap Lite - CMS on PHP