@@ -126,8 +126,8 @@ |
||
| 126 | 126 | public $usage_bill_time; // Is the time spent on project must be invoiced or not |
| 127 | 127 | |
| 128 | 128 | /** |
| 129 | - * @var integer Event organization: Use Event Organization |
|
| 130 | - */ |
|
| 129 | + * @var integer Event organization: Use Event Organization |
|
| 130 | + */ |
|
| 131 | 131 | public $usage_organize_event; |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -916,7 +916,7 @@ |
||
| 916 | 916 | /** |
| 917 | 917 | * @var array $suffix2numAsked map HTTP query parameter suffixes (like '1_0') to line indices so that |
| 918 | 918 | * extrafields from HTTP query can be assigned to the correct dispatch line |
| 919 | - */ |
|
| 919 | + */ |
|
| 920 | 920 | $suffix2numAsked = array(); |
| 921 | 921 | $dispatchLines = array(); |
| 922 | 922 | |
@@ -156,7 +156,7 @@ |
||
| 156 | 156 | * $price Can be set to update AWP (Average Weighted Price) when you make a stock increase |
| 157 | 157 | * $dlc Eat-by date. Will be used if lot does not exists yet and will be created. |
| 158 | 158 | * $dluo Sell-by date. Will be used if lot does not exists yet and will be created. |
| 159 | - * |
|
| 159 | + * |
|
| 160 | 160 | * @param int $product_id Id product id {@min 1} {@from body} {@required true} |
| 161 | 161 | * @param int $warehouse_id Id warehouse {@min 1} {@from body} {@required true} |
| 162 | 162 | * @param float $qty Qty to add (Use negative value for a stock decrease) {@from body} {@required true} |
@@ -21,11 +21,11 @@ |
||
| 21 | 21 | protected $openned = false; |
| 22 | 22 | protected $filename; |
| 23 | 23 | protected $pclzip; |
| 24 | - /** |
|
| 25 | - * Class constructor |
|
| 26 | - * |
|
| 27 | - * @throws PclZipProxyException |
|
| 28 | - */ |
|
| 24 | + /** |
|
| 25 | + * Class constructor |
|
| 26 | + * |
|
| 27 | + * @throws PclZipProxyException |
|
| 28 | + */ |
|
| 29 | 29 | public function __construct($forcedir='') |
| 30 | 30 | { |
| 31 | 31 | if (! class_exists('PclZip')) { |
@@ -17,11 +17,11 @@ |
||
| 17 | 17 | { |
| 18 | 18 | protected $zipArchive; |
| 19 | 19 | protected $filename; |
| 20 | - /** |
|
| 21 | - * Class constructor |
|
| 22 | - * |
|
| 23 | - * @throws PhpZipProxyException |
|
| 24 | - */ |
|
| 20 | + /** |
|
| 21 | + * Class constructor |
|
| 22 | + * |
|
| 23 | + * @throws PhpZipProxyException |
|
| 24 | + */ |
|
| 25 | 25 | public function __construct() |
| 26 | 26 | { |
| 27 | 27 | if (! class_exists('ZipArchive')) { |
@@ -10,41 +10,41 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | class SegmentIterator implements RecursiveIterator |
| 12 | 12 | { |
| 13 | - private $ref; |
|
| 14 | - private $key; |
|
| 15 | - public function __construct(array $ref) |
|
| 16 | - { |
|
| 17 | - $this->ref = $ref; |
|
| 18 | - $this->key = 0; |
|
| 19 | - $this->keys = array_keys($this->ref); |
|
| 20 | - } |
|
| 21 | - public function hasChildren() |
|
| 22 | - { |
|
| 23 | - return $this->valid() && $this->current() instanceof Segment; |
|
| 24 | - } |
|
| 25 | - public function current() |
|
| 26 | - { |
|
| 27 | - return $this->ref[$this->keys[$this->key]]; |
|
| 28 | - } |
|
| 29 | - function getChildren() |
|
| 30 | - { |
|
| 31 | - return new self($this->current()->children); |
|
| 32 | - } |
|
| 33 | - public function key() |
|
| 34 | - { |
|
| 35 | - return $this->key; |
|
| 36 | - } |
|
| 37 | - public function valid() |
|
| 38 | - { |
|
| 39 | - return array_key_exists($this->key, $this->keys); |
|
| 40 | - } |
|
| 41 | - public function rewind() |
|
| 42 | - { |
|
| 43 | - $this->key = 0; |
|
| 44 | - } |
|
| 45 | - public function next() |
|
| 46 | - { |
|
| 47 | - $this->key ++; |
|
| 48 | - } |
|
| 13 | + private $ref; |
|
| 14 | + private $key; |
|
| 15 | + public function __construct(array $ref) |
|
| 16 | + { |
|
| 17 | + $this->ref = $ref; |
|
| 18 | + $this->key = 0; |
|
| 19 | + $this->keys = array_keys($this->ref); |
|
| 20 | + } |
|
| 21 | + public function hasChildren() |
|
| 22 | + { |
|
| 23 | + return $this->valid() && $this->current() instanceof Segment; |
|
| 24 | + } |
|
| 25 | + public function current() |
|
| 26 | + { |
|
| 27 | + return $this->ref[$this->keys[$this->key]]; |
|
| 28 | + } |
|
| 29 | + function getChildren() |
|
| 30 | + { |
|
| 31 | + return new self($this->current()->children); |
|
| 32 | + } |
|
| 33 | + public function key() |
|
| 34 | + { |
|
| 35 | + return $this->key; |
|
| 36 | + } |
|
| 37 | + public function valid() |
|
| 38 | + { |
|
| 39 | + return array_key_exists($this->key, $this->keys); |
|
| 40 | + } |
|
| 41 | + public function rewind() |
|
| 42 | + { |
|
| 43 | + $this->key = 0; |
|
| 44 | + } |
|
| 45 | + public function next() |
|
| 46 | + { |
|
| 47 | + $this->key ++; |
|
| 48 | + } |
|
| 49 | 49 | } |
| 50 | 50 | |
@@ -156,17 +156,17 @@ |
||
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | /** |
| 159 | - * Function to replace macros for invoice short and long month, invoice year |
|
| 160 | - * |
|
| 161 | - * Substitution occur when the invoice is generated, not considering the invoice date |
|
| 162 | - * so do not (re)generate in a diferent date than the one that the invoice belongs to |
|
| 163 | - * Perhaps it would be better to use the invoice issued date but I still do not know |
|
| 164 | - * how to get it here |
|
| 165 | - * |
|
| 166 | - * Miguel Erill 09/04/2017 |
|
| 167 | - * |
|
| 168 | - * @param string $value String to convert |
|
| 169 | - */ |
|
| 159 | + * Function to replace macros for invoice short and long month, invoice year |
|
| 160 | + * |
|
| 161 | + * Substitution occur when the invoice is generated, not considering the invoice date |
|
| 162 | + * so do not (re)generate in a diferent date than the one that the invoice belongs to |
|
| 163 | + * Perhaps it would be better to use the invoice issued date but I still do not know |
|
| 164 | + * how to get it here |
|
| 165 | + * |
|
| 166 | + * Miguel Erill 09/04/2017 |
|
| 167 | + * |
|
| 168 | + * @param string $value String to convert |
|
| 169 | + */ |
|
| 170 | 170 | public function macroReplace($text) |
| 171 | 171 | { |
| 172 | 172 | include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; |
@@ -15,5 +15,5 @@ |
||
| 15 | 15 | // If possible, use a disk cache to enable attaching large attachments etc. |
| 16 | 16 | // You can override the default temporary directory by setting the TMPDIR environment variable. |
| 17 | 17 | if (@is_writable($tmpDir = sys_get_temp_dir())) { |
| 18 | - $preferences->setTempDir($tmpDir)->setCacheType('disk'); |
|
| 18 | + $preferences->setTempDir($tmpDir)->setCacheType('disk'); |
|
| 19 | 19 | } |
@@ -6,177 +6,177 @@ |
||
| 6 | 6 | |
| 7 | 7 | function generateUpToDateMimeArray() |
| 8 | 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); |
|
| 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 | 180 | } |
| 181 | 181 | |
| 182 | 182 | generateUpToDateMimeArray(); |