[ Index ] |
MailPress 7.2 |
[ Index ] [ Classes ] [ Functions ] [ Variables ] [ Constants ] [ Statistics ] |
[Summary view] [Print] [Text view]
1 #!/usr/bin/php 2 3 <?php 4 define('APACHE_MIME_TYPES_URL', 'https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types'); 5 define('FREEDESKTOP_XML_URL', 'https://raw.github.com/minad/mimemagic/master/script/freedesktop.org.xml'); 6 7 function generateUpToDateMimeArray() 8 { 9 $preamble = "<?php\n\n"; 10 $preamble .= "/*\n"; 11 $preamble .= " * This file is part of SwiftMailer.\n"; 12 $preamble .= " * (c) 2004-2009 Chris Corbyn\n *\n"; 13 $preamble .= " * For the full copyright and license information, please view the LICENSE\n"; 14 $preamble .= " * file that was distributed with this source code.\n *\n"; 15 $preamble .= " * autogenerated using https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types\n"; 16 $preamble .= " * and https://raw.github.com/minad/mimemagic/master/script/freedesktop.org.xml\n"; 17 $preamble .= " */\n\n"; 18 $preamble .= "/*\n"; 19 $preamble .= " * List of MIME type automatically detected in Swift Mailer.\n"; 20 $preamble .= " */\n\n"; 21 $preamble .= "// You may add or take away what you like (lowercase required)\n\n"; 22 23 // get current mime types files 24 $mime_types = @file_get_contents(APACHE_MIME_TYPES_URL); 25 $mime_xml = @file_get_contents(FREEDESKTOP_XML_URL); 26 27 // prepare valid mime types 28 $valid_mime_types = []; 29 30 // split mime type and extensions eg. "video/x-matroska mkv mk3d mks" 31 if (false !== preg_match_all('/^#?([a-z0-9\-\+\/\.]+)[\t]+(.*)$/miu', $mime_types, $matches)) { 32 // collection of predefined mimetypes (bugfix for wrong resolved or missing mime types) 33 $valid_mime_types_preset = [ 34 'php' => 'application/x-php', 35 'php3' => 'application/x-php', 36 'php4' => 'application/x-php', 37 'php5' => 'application/x-php', 38 'zip' => 'application/zip', 39 'gif' => 'image/gif', 40 'png' => 'image/png', 41 'css' => 'text/css', 42 'js' => 'text/javascript', 43 'txt' => 'text/plain', 44 'aif' => 'audio/x-aiff', 45 'aiff' => 'audio/x-aiff', 46 'avi' => 'video/avi', 47 'bmp' => 'image/bmp', 48 'bz2' => 'application/x-bz2', 49 'csv' => 'text/csv', 50 'dmg' => 'application/x-apple-diskimage', 51 'doc' => 'application/msword', 52 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 53 'eml' => 'message/rfc822', 54 'aps' => 'application/postscript', 55 'exe' => 'application/x-ms-dos-executable', 56 'flv' => 'video/x-flv', 57 'gz' => 'application/x-gzip', 58 'hqx' => 'application/stuffit', 59 'htm' => 'text/html', 60 'html' => 'text/html', 61 'jar' => 'application/x-java-archive', 62 'jpeg' => 'image/jpeg', 63 'jpg' => 'image/jpeg', 64 'm3u' => 'audio/x-mpegurl', 65 'm4a' => 'audio/mp4', 66 'mdb' => 'application/x-msaccess', 67 'mid' => 'audio/midi', 68 'midi' => 'audio/midi', 69 'mov' => 'video/quicktime', 70 'mp3' => 'audio/mpeg', 71 'mp4' => 'video/mp4', 72 'mpeg' => 'video/mpeg', 73 'mpg' => 'video/mpeg', 74 'odg' => 'vnd.oasis.opendocument.graphics', 75 'odp' => 'vnd.oasis.opendocument.presentation', 76 'odt' => 'vnd.oasis.opendocument.text', 77 'ods' => 'vnd.oasis.opendocument.spreadsheet', 78 'ogg' => 'audio/ogg', 79 'pdf' => 'application/pdf', 80 'ppt' => 'application/vnd.ms-powerpoint', 81 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 82 'ps' => 'application/postscript', 83 'rar' => 'application/x-rar-compressed', 84 'rtf' => 'application/rtf', 85 'tar' => 'application/x-tar', 86 'sit' => 'application/x-stuffit', 87 'svg' => 'image/svg+xml', 88 'tif' => 'image/tiff', 89 'tiff' => 'image/tiff', 90 'ttf' => 'application/x-font-truetype', 91 'vcf' => 'text/x-vcard', 92 'wav' => 'audio/wav', 93 'wma' => 'audio/x-ms-wma', 94 'wmv' => 'audio/x-ms-wmv', 95 'xls' => 'application/vnd.ms-excel', 96 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 97 'xml' => 'application/xml', 98 ]; 99 100 // wrap array for generating file 101 foreach ($valid_mime_types_preset as $extension => $mime_type) { 102 // generate array for mimetype to extension resolver (only first match) 103 $valid_mime_types[$extension] = "'{$extension}' => '{$mime_type}'"; 104 } 105 106 // all extensions from second match 107 foreach ($matches[2] as $i => $extensions) { 108 // explode multiple extensions from string 109 $extensions = explode(' ', strtolower($extensions)); 110 111 // force array for foreach 112 if (!is_array($extensions)) { 113 $extensions = [$extensions]; 114 } 115 116 foreach ($extensions as $extension) { 117 // get mime type 118 $mime_type = $matches[1][$i]; 119 120 // check if string length lower than 10 121 if (strlen($extension) < 10) { 122 if (!isset($valid_mime_types[$mime_type])) { 123 // generate array for mimetype to extension resolver (only first match) 124 $valid_mime_types[$extension] = "'{$extension}' => '{$mime_type}'"; 125 } 126 } 127 } 128 } 129 } 130 131 $xml = simplexml_load_string($mime_xml); 132 133 foreach ($xml as $node) { 134 // check if there is no pattern 135 if (!isset($node->glob['pattern'])) { 136 continue; 137 } 138 139 // get all matching extensions from match 140 foreach ((array) $node->glob['pattern'] as $extension) { 141 // skip none glob extensions 142 if (false === strpos($extension, '.')) { 143 continue; 144 } 145 146 // remove get only last part 147 $extension = explode('.', strtolower($extension)); 148 $extension = end($extension); 149 } 150 151 if (isset($node->glob['pattern'][0])) { 152 // mime type 153 $mime_type = strtolower((string) $node['type']); 154 155 // get first extension 156 $extension = strtolower(trim($node->glob['ddpattern'][0], '*.')); 157 158 // skip none glob extensions and check if string length between 1 and 10 159 if (false !== strpos($extension, '.') || strlen($extension) < 1 || strlen($extension) > 9) { 160 continue; 161 } 162 163 // check if string length lower than 10 164 if (!isset($valid_mime_types[$mime_type])) { 165 // generate array for mimetype to extension resolver (only first match) 166 $valid_mime_types[$extension] = "'{$extension}' => '{$mime_type}'"; 167 } 168 } 169 } 170 171 // full list of valid extensions only 172 $valid_mime_types = array_unique($valid_mime_types); 173 ksort($valid_mime_types); 174 175 // combine mime types and extensions array 176 $output = "$preamble\$swift_mime_types = array(\n ".implode(",\n ", $valid_mime_types)."\n);"; 177 178 // write mime_types.php config file 179 @file_put_contents('./mime_types.php', $output); 180 } 181 182 generateUpToDateMimeArray();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue May 19 15:55:14 2020 | Cross-referenced by PHPXref 0.7.1 |