Subversion Repositories fileformats

Rev

Rev 2 | Rev 4 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 3
Line 31... Line 31...
31
                }
31
                }
32
 
32
 
33
                return false;
33
                return false;
34
        }
34
        }
35
 
35
 
36
        public static function getDescription($file, $filename1=__DIR__.'/filetypes.conf', $filename2=__DIR__.'/filetypes.local') {
36
        public static function getDescription($file, $filenames=array(__DIR__.'/filetypes.local', __DIR__.'/filetypes.conf')) {
37
                // TODO: Make it multi-lang
37
                // TODO: Make it multi-lang
38
 
38
 
39
                $ini = !file_exists($filename1) ? array() : parse_ini_file($filename1, true, INI_SCANNER_RAW);
-
 
40
                if (!isset($ini['OidHeader']))     $ini['OidHeader']     = array();
-
 
41
                if (!isset($ini['GuidHeader']))    $ini['GuidHeader']    = array();
-
 
42
                if (!isset($ini['FileExtension'])) $ini['FileExtension'] = array();
39
                $inis = array();
43
                if (!isset($ini['MimeType']))      $ini['MimeType']      = array();
40
                foreach ($filenames as $num => $filename) {
44
 
-
 
45
                $ini2 = !file_exists($filename2) ? array() : parse_ini_file($filename2, true, INI_SCANNER_RAW);
41
                        $inis[$num] = !file_exists($filename) ? array() : parse_ini_file($filename, true, INI_SCANNER_RAW);
46
                if (!isset($ini2['OidHeader']))     $ini2['OidHeader']     = array();
42
                        if (!isset($inis[$num]['OidHeader']))     $inis[$num]['OidHeader']     = array();
47
                if (!isset($ini2['GuidHeader']))    $ini2['GuidHeader']    = array();
43
                        if (!isset($inis[$num]['GuidHeader']))    $inis[$num]['GuidHeader']    = array();
48
                if (!isset($ini2['FileExtension'])) $ini2['FileExtension'] = array();
44
                        if (!isset($inis[$num]['FileExtension'])) $inis[$num]['FileExtension'] = array();
49
                if (!isset($ini2['MimeType']))      $ini2['MimeType']      = array();
45
                        if (!isset($inis[$num]['MimeType']))      $inis[$num]['MimeType']      = array();
-
 
46
                }
50
 
47
 
51
                if (is_readable($file)) {
48
                if (is_readable($file)) {
52
                        $h = fopen($file, 'r');
49
                        $h = fopen($file, 'r');
53
                        $line = trim(fgets($h, 128));
50
                        $line = trim(fgets($h, 128));
54
                        if (($line[0] == '[') && ($line[strlen($line)-1] == ']')) {
51
                        if (($line[0] == '[') && ($line[strlen($line)-1] == ']')) {
55
                                $line = substr($line, 1, strlen($line)-2);
52
                                $line = substr($line, 1, strlen($line)-2);
56
                                if (isset($ini2['OidHeader'][$line]))  return $ini2['OidHeader'][$line];
53
                                foreach ($inis as $ini) {
57
                                if (isset($ini['OidHeader'][$line]))   return $ini['OidHeader'][$line];
54
                                        if (isset($ini['OidHeader'][$line]))  return $ini['OidHeader'][$line];
58
                                if (isset($ini2['GuidHeader'][$line])) return $ini2['GuidHeader'][$line];
-
 
59
                                if (isset($ini['GuidHeader'][$line]))  return $ini['GuidHeader'][$line];
-
 
60
                        }
55
                                }
61
                        fclose($h);
56
                                foreach ($inis as $ini) {
-
 
57
                                        if (isset($ini['GuidHeader'][$line])) return $ini['GuidHeader'][$line];
62
                }
58
                                }
63
 
-
 
64
                foreach ($ini2['FileExtension'] as $ext => $name) {
-
 
65
                        if (strtoupper(substr($file, -strlen($ext)-1)) == strtoupper('.'.$ext)) {
-
 
66
                                return $name;
-
 
67
                        }
59
                        }
-
 
60
                        fclose($h);
68
                }
61
                }
69
 
62
 
-
 
63
                foreach ($inis as $ini) {
70
                foreach ($ini['FileExtension'] as $ext => $name) {
64
                        foreach ($ini['FileExtension'] as $ext => $name) {
71
                        if (strtoupper(substr($file, -strlen($ext)-1)) == strtoupper('.'.$ext)) {
65
                                if (strtoupper(substr($file, -strlen($ext)-1)) == strtoupper('.'.$ext)) {
72
                                return $name;
66
                                        return $name;
73
                        }
67
                                }
74
                }
68
                        }
-
 
69
                }
75
 
70
 
76
                $mime = false;
71
                $mime = false;
77
                if (function_exists('mime_content_type')) {
72
                if (function_exists('mime_content_type')) {
78
                        $mime = @mime_content_type($file);
73
                        $mime = @mime_content_type($file);
79
                }
74
                }
80
                if (!$mime) {
75
                if (!$mime) {
81
                        $mime = self::getMimeType($file);
76
                        $mime = self::getMimeType($file);
82
                }
77
                }
83
                if ($mime) {
78
                if ($mime) {
84
                        if (isset($ini2['MimeType'][$mime])) return $ini2['MimeType'][$mime];
79
                        foreach ($inis as $ini) {
85
                        if (isset($ini['MimeType'][$mime]))  return $ini['MimeType'][$mime];
80
                                if (isset($ini['MimeType'][$mime]))  return $ini['MimeType'][$mime];
86
                }
81
                        }
-
 
82
                }
87
 
83
 
88
                return $ini['Static']['LngUnknown'];
84
                return $ini['Static']['LngUnknown'];
89
        }
85
        }
90
 
86
 
91
}
87
}