22 "application/msword" =>
"mime-wordprocessing",
23 "application/ogg" =>
"audio-x-generic",
24 "application/pdf" =>
"mime-pdf",
25 "application/postscript" =>
"mime-wordprocessing",
26 "application/rtf" =>
"mime-wordprocessing",
27 "application/vnd.lotus-1-2-3" =>
"mime-spreadsheet",
28 "application/vnd.ms-excel" =>
"mime-spreadsheet",
29 "application/vnd.ms-powerpoint" =>
"mime-presentation",
30 "application/vnd.oasis.opendocument.presentation" =>
"mime-presentation",
31 "application/vnd.oasis.opendocument.spreadsheet" =>
"mime-spreadsheet",
32 "application/vnd.oasis.opendocument.text" =>
"mime-wordprocessing",
33 "application/vnd.oasis.opendocument.graphics" =>
"mime-vectorgfx",
34 "application/vnd.stardivision.calc" =>
"mime-spreadsheet",
35 "application/vnd.stardivision.impress" =>
"mime-presentation",
36 "application/vnd.stardivision.writer" =>
"mime-wordprocessing",
37 "application/vnd.sun.xml.calc" =>
"mime-spreadsheet",
38 "application/vnd.sun.xml.impress" =>
"mime-presentation",
39 "application/vnd.sun.xml.writer" =>
"mime-wordprocessing",
40 "application/vnd.sun.xml.writer.global" =>
"mime-wordprocessing",
41 "application/vnd.sun.xml.draw" =>
"mime-vectorgfx",
42 "application/wordperfect" =>
"mime-wordprocessing",
43 "application/x-7z-compressed" =>
"mime-tgz",
44 "application/x-abiword" =>
"mime-wordprocessing",
45 "application/x-applix-spreadsheet" =>
"mime-spreadsheet",
46 "application/x-applix-word" =>
"mime-wordprocessing",
47 "application/x-archive" =>
"mime-tar",
48 "application/x-arj" =>
"mime-tgz",
49 "application/x-bzip-compressed-tar" =>
"mime-tgz",
50 "application/x-bzip" =>
"mime-tgz",
51 "application/x-compressed-tar" =>
"mime-tgz",
52 "application/x-compress" =>
"mime-tgz",
53 "application/x-cpio-compressed" =>
"mime-tgz",
54 "application/x-cpio" =>
"mime-tgz",
55 "application/x-deb" =>
"mime-tgz",
56 "application/x-dvi" =>
"mime-wordprocessing",
57 "application/x-executable" =>
"application/x-executable",
58 "application/x-font-afm" =>
"font-x-generic",
59 "application/x-font-bdf" =>
"font-x-generic",
60 "application/x-font-linux-psf" =>
"font-x-generic",
61 "application/x-font-pcf" =>
"font-x-generic",
62 "application/x-font-sunos-news" =>
"font-x-generic",
63 "application/x-font-ttf" =>
"font-x-generic",
64 "application/x-gnumeric" =>
"mime-spreadsheet",
65 "application/x-gzip" =>
"mime-tgz",
66 "application/xhtml+xml" =>
"text-html",
67 "application/x-killustrator" =>
"mime-vectorgfx",
68 "application/x-kpresenter" =>
"mime-presentation",
69 "application/x-kspread" =>
"mime-spreadsheet",
70 "application/x-kword" =>
"mime-wordprocessing",
71 "application/x-ms-dos-executable" =>
"application/x-executable",
72 "application/x-perl" =>
"mime-shellscript",
73 "application/x-php" =>
"text-html",
74 "application/x-python-bytecode" =>
"mime-shellscript",
75 "application/x-rar" =>
"mime-tgz",
76 "application/x-rpm" =>
"mime-rpm",
77 "application/x-shellscript" =>
"mime-shellscript",
78 "application/x-shockwave-flash" =>
"video-x-generic",
79 "application/x-tar" =>
"mime-tar",
80 "application/x-tarz" =>
"mime-tgz",
81 "application/x-tex" =>
"mime-tex",
82 "application/x-zip" =>
"mime-zip",
83 "application/zip" =>
"mime-zip",
84 "application" =>
"mime-zip",
85 "audio" =>
"mime-sound",
86 "image" =>
"mime-image2",
87 "video" =>
"mime-video",
88 "image/jpeg" =>
"mime-image",
89 "text/html" =>
"mime-html",
90 "text/xml" =>
"mime-xml",
91 "text/x-c++" =>
"mime-source_cpp",
92 "text/x-c" =>
"mime-source_c",
93 "text/x-c-header" =>
"mime-source_h",
94 "text/x-php" =>
"mime-source_php",
96 "text/vnd.wap.wml" =>
"mime-html",
97 "text/x-csh" =>
"mime-shellscript",
98 "text/x-python" =>
"mime-shellscript",
99 "text/x-sh" =>
"mime-shellscript",
100 "text/x-vcalendar" =>
"mime-vcalendar",
101 "text/x-vcard" =>
"mime-address-book",
102 "text/x-zsh" =>
"mime-shellscript",
103 "text/x-makefile" =>
"mime-make",
104 "x-font-afm" =>
"font-x-generic"
112 $tmime = explode(
";", $sysmime);
113 $mime = trim($tmime[0]);
115 if (isset($mimeIcon[$mime])) {
116 $icon = $mimeIcon[$mime] .
".png";
118 $p = strpos($mime,
'/');
119 $mime = substr($mime, 0, $p);
120 if (isset($mimeIcon[$mime])) {
121 $icon = $mimeIcon[$mime] .
".png";
135 if (!file_exists($f))
return false;
138 if (
$ret !==
false) {
142 $sys = trim(shell_exec(sprintf(
"file --mime -b %s", escapeshellarg($f))));
144 $sys = strtok($sys,
" ;\n\t");
146 if (preg_match(
'/Makefile/', $fn))
return 'text/x-makefile';
147 if (preg_match(
'/ASCII C\+\+/', $txt)) {
148 if (preg_match(
'/\.h$/', $fn))
return 'text/x-c-header';
151 if (preg_match(
'/PHP script/', $txt))
return 'text/x-php';
153 if (preg_match(
'/zip$/', $sys) || (preg_match(
'/octet-stream$/', $sys))) {
155 if (preg_match(
'/OpenOffice/', $txt)) {
156 if (preg_match(
'/\.sxw$/', $fn))
return 'application/vnd.sun.xml.writer';
157 if (preg_match(
'/\.sxc$/', $fn))
return 'application/vnd.sun.xml.calc';
158 if (preg_match(
'/\.sxi$/', $fn))
return 'application/vnd.sun.xml.impress';
159 if (preg_match(
'/\.sxd$/', $fn))
return 'application/vnd.sun.xml.draw';
160 if (preg_match(
'/\.sxg$/', $fn))
return 'application/vnd.sun.xml.writer.global';
161 return 'application/vnd.sun.xml.writer';
163 if (preg_match(
'/OpenDocument/', $txt)) {
164 if (preg_match(
'/\.odp$/', $fn))
return 'application/vnd.oasis.opendocument.presentation';
165 if (preg_match(
'/\.odt$/', $fn))
return 'application/vnd.oasis.opendocument.text';
166 if (preg_match(
'/\.ods$/', $fn))
return 'application/vnd.oasis.opendocument.spreadsheet';
167 if (preg_match(
'/\.odg$/', $fn))
return 'application/vnd.oasis.opendocument.graphics';
168 return 'application/vnd.oasis.opendocument.text';
171 if (preg_match(
'/\.sxw$/', $fn))
return 'application/vnd.sun.xml.writer';
172 if (preg_match(
'/\.sxc$/', $fn))
return 'application/vnd.sun.xml.calc';
173 if (preg_match(
'/\.sxi$/', $fn))
return 'application/vnd.sun.xml.impress';
174 if (preg_match(
'/\.sxd$/', $fn))
return 'application/vnd.sun.xml.draw';
175 if (preg_match(
'/\.sxg$/', $fn))
return 'application/vnd.sun.xml.writer.global';
176 if (preg_match(
'/\.odp$/', $fn))
return 'application/vnd.oasis.opendocument.presentation';
177 if (preg_match(
'/\.odt$/', $fn))
return 'application/vnd.oasis.opendocument.text';
178 if (preg_match(
'/\.ods$/', $fn))
return 'application/vnd.oasis.opendocument.spreadsheet';
179 if (preg_match(
'/\.odg$/', $fn))
return 'application/vnd.oasis.opendocument.graphics';
184 if (preg_match(
'/^XML/', $txt))
return 'text/xml';
187 if (preg_match(
'/\.xls$/', $fn))
return 'application/vnd.ms-excel';
188 if (preg_match(
'/\.doc$/', $fn))
return 'application/msword';
189 if (preg_match(
'/\.ppt$/', $fn))
return 'application/vnd.ms-powerpoint';
191 if ($sys ==
'application/msword') {
192 if (preg_match(
'/\.xls$/', $fn))
return 'application/vnd.ms-excel';
193 if (preg_match(
'/\.ppt$/', $fn))
return 'application/vnd.ms-powerpoint';
196 return strtok($sys,
" ;\n\t");
201 if (
$ret !==
false) {
205 $txt = trim(shell_exec(sprintf(
"file -b %s", escapeshellarg($f))));
206 if ($txt ==
'data') {
207 if (preg_match(
'/\.ods$/', $f)) $txt =
'OpenDocument Spreadsheet';
208 else if (preg_match(
'/\.odt$/', $f)) $txt =
'OpenDocument Text';
209 else if (preg_match(
'/\.odp$/', $f)) $txt =
'OpenDocument Presentation';
210 else if (preg_match(
'/\.odg$/', $f)) $txt =
'OpenDocument Drawing';
212 if (!$txt)
return " ";
220 include_once (
"MimeExtension.php");
222 $ext = $exts[$smime];
224 return strtok($ext,
" \n\t");
244 $conf = array_merge($conf_user, $conf_global);
246 foreach ($conf as $rule) {
248 if (preg_match(
"/\.\Q$ext\E$/i",
$filename)) {
260 include_once (
'WHAT/Lib.Prefix.php');
264 $conf_file = sprintf(
"%s%sadmin%smime-user.conf",
DEFAULT_PUBDIR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR);
265 if (!file_exists($conf_file) || !is_readable($conf_file)) {
269 $xml = simplexml_load_file($conf_file);
270 if ($xml ===
false) {
271 error_log(__FUNCTION__ .
" " . sprintf(
"Could not load user MIME config '%s'.", $conf_file));
275 foreach ($xml->mime as $mimeNode) {
282 $rule[$attrName] = (string)$mimeNode[$attrName];
284 array_push($rules, $rule);
294 include_once (
'WHAT/Lib.Prefix.php');
298 $conf_file = sprintf(
"%s%sadmin%smime.conf",
DEFAULT_PUBDIR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR);
299 $xml = simplexml_load_file($conf_file);
300 if ($xml ===
false) {
301 error_log(__FUNCTION__ .
" " . sprintf(
"Could not load MIME config '%s'.", $conf_file));
305 foreach ($xml->mime as $mimeNode) {
312 $rule[$attrName] = (string)$mimeNode[$attrName];
314 array_push($rules, $rule);
326 if (file_exists(
$file)) {
327 $nbpages = intval(trim(shell_exec(sprintf(
'grep -c "/Type[[:space:]]*/Page>" %s', escapeshellarg(
$file)))));