@@ -499,7 +499,7 @@ |
||
499 | 499 | $height *= self::PIXEL_TO_CM; |
500 | 500 | $xml = <<<IMG |
501 | 501 | <draw:frame draw:style-name="fr1" draw:name="$filename" text:anchor-type="aschar" svg:width="{$width}cm" svg:height="{$height}cm" draw:z-index="3"><draw:image xlink:href="Pictures/$file" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/></draw:frame> |
502 | -IMG; |
|
502 | +img; |
|
503 | 503 | $this->images[$value] = $file; |
504 | 504 | $this->setVars($key, $xml, false); |
505 | 505 | return $this; |
@@ -31,18 +31,18 @@ discard block |
||
31 | 31 | class Odf |
32 | 32 | { |
33 | 33 | protected $config = array( |
34 | - 'ZIP_PROXY' => 'PclZipProxy', // PclZipProxy, PhpZipProxy |
|
34 | + 'ZIP_PROXY' => 'PclZipProxy', // PclZipProxy, PhpZipProxy |
|
35 | 35 | 'DELIMITER_LEFT' => '{', |
36 | 36 | 'DELIMITER_RIGHT' => '}', |
37 | 37 | 'PATH_TO_TMP' => '/tmp' |
38 | 38 | ); |
39 | 39 | protected $file; |
40 | - protected $contentXml; // To store content of content.xml file |
|
41 | - protected $metaXml; // To store content of meta.xml file |
|
42 | - protected $stylesXml; // To store content of styles.xml file |
|
43 | - protected $manifestXml; // To store content of META-INF/manifest.xml file |
|
40 | + protected $contentXml; // To store content of content.xml file |
|
41 | + protected $metaXml; // To store content of meta.xml file |
|
42 | + protected $stylesXml; // To store content of styles.xml file |
|
43 | + protected $manifestXml; // To store content of META-INF/manifest.xml file |
|
44 | 44 | protected $tmpfile; |
45 | - protected $tmpdir=''; |
|
45 | + protected $tmpdir = ''; |
|
46 | 46 | protected $images = array(); |
47 | 47 | protected $vars = array(); |
48 | 48 | protected $segments = array(); |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | public $creator; |
51 | 51 | public $title; |
52 | 52 | public $subject; |
53 | - public $userdefined=array(); |
|
53 | + public $userdefined = array(); |
|
54 | 54 | |
55 | 55 | const PIXEL_TO_CM = 0.026458333; |
56 | 56 | const FIND_TAGS_REGEX = '/<([A-Za-z0-9]+)(?:\s([A-Za-z]+(?:\-[A-Za-z]+)?(?:=(?:".*?")|(?:[0-9]+))))*(?:(?:\s\/>)|(?:>(.*)<\/\1>))/s'; |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | { |
69 | 69 | clearstatcache(); |
70 | 70 | |
71 | - if (! is_array($config)) { |
|
71 | + if (!is_array($config)) { |
|
72 | 72 | throw new OdfException('Configuration data must be provided as array'); |
73 | 73 | } |
74 | 74 | foreach ($config as $configKey => $configValue) { |
@@ -78,12 +78,12 @@ discard block |
||
78 | 78 | } |
79 | 79 | |
80 | 80 | $md5uniqid = md5(uniqid()); |
81 | - if ($this->config['PATH_TO_TMP']) $this->tmpdir = preg_replace('|[\/]$|', '', $this->config['PATH_TO_TMP']); // Remove last \ or / |
|
82 | - $this->tmpdir .= ($this->tmpdir?'/':'').$md5uniqid; |
|
83 | - $this->tmpfile = $this->tmpdir.'/'.$md5uniqid.'.odt'; // We keep .odt extension to allow OpenOffice usage during debug. |
|
81 | + if ($this->config['PATH_TO_TMP']) $this->tmpdir = preg_replace('|[\/]$|', '', $this->config['PATH_TO_TMP']); // Remove last \ or / |
|
82 | + $this->tmpdir .= ($this->tmpdir ? '/' : '').$md5uniqid; |
|
83 | + $this->tmpfile = $this->tmpdir.'/'.$md5uniqid.'.odt'; // We keep .odt extension to allow OpenOffice usage during debug. |
|
84 | 84 | |
85 | 85 | // A working directory is required for some zip proxy like PclZipProxy |
86 | - if (in_array($this->config['ZIP_PROXY'], array('PclZipProxy')) && ! is_dir($this->config['PATH_TO_TMP'])) { |
|
86 | + if (in_array($this->config['ZIP_PROXY'], array('PclZipProxy')) && !is_dir($this->config['PATH_TO_TMP'])) { |
|
87 | 87 | throw new OdfException('Temporary directory '.$this->config['PATH_TO_TMP'].' must exists'); |
88 | 88 | } |
89 | 89 | |
@@ -96,8 +96,8 @@ discard block |
||
96 | 96 | $zipHandler = $this->config['ZIP_PROXY']; |
97 | 97 | if (!defined('PCLZIP_TEMPORARY_DIR')) define('PCLZIP_TEMPORARY_DIR', $this->tmpdir); |
98 | 98 | include_once 'zip/'.$zipHandler.'.php'; |
99 | - if (! class_exists($this->config['ZIP_PROXY'])) { |
|
100 | - throw new OdfException($this->config['ZIP_PROXY'] . ' class not found - check your php settings'); |
|
99 | + if (!class_exists($this->config['ZIP_PROXY'])) { |
|
100 | + throw new OdfException($this->config['ZIP_PROXY'].' class not found - check your php settings'); |
|
101 | 101 | } |
102 | 102 | $this->file = new $zipHandler($this->tmpdir); |
103 | 103 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | */ |
145 | 145 | public function setVars($key, $value, $encode = true, $charset = 'ISO-8859') |
146 | 146 | { |
147 | - $tag = $this->config['DELIMITER_LEFT'] . $key . $this->config['DELIMITER_RIGHT']; |
|
147 | + $tag = $this->config['DELIMITER_LEFT'].$key.$this->config['DELIMITER_RIGHT']; |
|
148 | 148 | |
149 | 149 | // TODO Warning string may be: |
150 | 150 | // <text:span text:style-name="T13">{</text:span><text:span text:style-name="T12">aaa</text:span><text:span text:style-name="T13">}</text:span> |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | |
180 | 180 | // Check if the value includes html tags |
181 | 181 | if ($this->_hasHtmlTag($value) === true) { |
182 | - $value = strip_tags($value, '<br><strong><b><i><em><u><s><sub><sup><span>'); // remove html tags except the one into the list in second parameter |
|
182 | + $value = strip_tags($value, '<br><strong><b><i><em><u><s><sub><sup><span>'); // remove html tags except the one into the list in second parameter |
|
183 | 183 | |
184 | 184 | // Default styles for strong/b, i/em, u, s, sub & sup |
185 | 185 | $automaticStyles = array( |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | $convertedValue = $this->_replaceHtmlWithOdtTag($this->_getDataFromHtml($value), $customStyles, $fontDeclarations, $encode, $charset); |
198 | 198 | |
199 | 199 | foreach ($customStyles as $key => $val) { |
200 | - array_push($automaticStyles, '<style:style style:name="customStyle' . $key . '" style:family="text">' . $val . '</style:style>'); |
|
200 | + array_push($automaticStyles, '<style:style style:name="customStyle'.$key.'" style:family="text">'.$val.'</style:style>'); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | // Join the styles and add them to the content xml |
@@ -207,16 +207,16 @@ discard block |
||
207 | 207 | $styles .= $style; |
208 | 208 | } |
209 | 209 | } |
210 | - $this->contentXml = str_replace('</office:automatic-styles>', $styles . '</office:automatic-styles>', $this->contentXml); |
|
210 | + $this->contentXml = str_replace('</office:automatic-styles>', $styles.'</office:automatic-styles>', $this->contentXml); |
|
211 | 211 | |
212 | 212 | // Join the font declarations and add them to the content xml |
213 | 213 | $fonts = ''; |
214 | 214 | foreach ($fontDeclarations as $font) { |
215 | - if (strpos($this->contentXml, 'style:name="' . $font . '"') === false) { |
|
216 | - $fonts .= '<style:font-face style:name="' . $font . '" svg:font-family="\'' . $font . '\'" />'; |
|
215 | + if (strpos($this->contentXml, 'style:name="'.$font.'"') === false) { |
|
216 | + $fonts .= '<style:font-face style:name="'.$font.'" svg:font-family="\''.$font.'\'" />'; |
|
217 | 217 | } |
218 | 218 | } |
219 | - $this->contentXml = str_replace('</office:font-face-decls>', $fonts . '</office:font-face-decls>', $this->contentXml); |
|
219 | + $this->contentXml = str_replace('</office:font-face-decls>', $fonts.'</office:font-face-decls>', $this->contentXml); |
|
220 | 220 | } else { |
221 | 221 | $convertedValue = $this->encode_chars($convertedValue, $encode, $charset); |
222 | 222 | $convertedValue = preg_replace('/(\r\n|\r|\n)/i', "<text:line-break/>", $convertedValue); |
@@ -253,23 +253,23 @@ discard block |
||
253 | 253 | break; |
254 | 254 | case 'strong': |
255 | 255 | case 'b': |
256 | - $odtResult .= '<text:span text:style-name="boldText">' . ($tag['children'] != null ? $this->_replaceHtmlWithOdtTag($tag['children'], $customStyles, $fontDeclarations, $encode) : $this->encode_chars($tag['innerText'], $encode, $charset)) . '</text:span>'; |
|
256 | + $odtResult .= '<text:span text:style-name="boldText">'.($tag['children'] != null ? $this->_replaceHtmlWithOdtTag($tag['children'], $customStyles, $fontDeclarations, $encode) : $this->encode_chars($tag['innerText'], $encode, $charset)).'</text:span>'; |
|
257 | 257 | break; |
258 | 258 | case 'i': |
259 | 259 | case 'em': |
260 | - $odtResult .= '<text:span text:style-name="italicText">' . ($tag['children'] != null ? $this->_replaceHtmlWithOdtTag($tag['children'], $customStyles, $fontDeclarations, $encode) : $this->encode_chars($tag['innerText'], $encode, $charset)) . '</text:span>'; |
|
260 | + $odtResult .= '<text:span text:style-name="italicText">'.($tag['children'] != null ? $this->_replaceHtmlWithOdtTag($tag['children'], $customStyles, $fontDeclarations, $encode) : $this->encode_chars($tag['innerText'], $encode, $charset)).'</text:span>'; |
|
261 | 261 | break; |
262 | 262 | case 'u': |
263 | - $odtResult .= '<text:span text:style-name="underlineText">' . ($tag['children'] != null ? $this->_replaceHtmlWithOdtTag($tag['children'], $customStyles, $fontDeclarations, $encode) : $this->encode_chars($tag['innerText'], $encode, $charset)) . '</text:span>'; |
|
263 | + $odtResult .= '<text:span text:style-name="underlineText">'.($tag['children'] != null ? $this->_replaceHtmlWithOdtTag($tag['children'], $customStyles, $fontDeclarations, $encode) : $this->encode_chars($tag['innerText'], $encode, $charset)).'</text:span>'; |
|
264 | 264 | break; |
265 | 265 | case 's': |
266 | - $odtResult .= '<text:span text:style-name="strikethroughText">' . ($tag['children'] != null ? $this->_replaceHtmlWithOdtTag($tag['children'], $customStyles, $fontDeclarations, $encode) : $this->encode_chars($tag['innerText'], $encode, $charset)) . '</text:span>'; |
|
266 | + $odtResult .= '<text:span text:style-name="strikethroughText">'.($tag['children'] != null ? $this->_replaceHtmlWithOdtTag($tag['children'], $customStyles, $fontDeclarations, $encode) : $this->encode_chars($tag['innerText'], $encode, $charset)).'</text:span>'; |
|
267 | 267 | break; |
268 | 268 | case 'sub': |
269 | - $odtResult .= '<text:span text:style-name="subText">' . ($tag['children'] != null ? $this->_replaceHtmlWithOdtTag($tag['children'], $customStyles, $fontDeclarations, $encode) : $this->encode_chars($tag['innerText'], $encode, $charset)) . '</text:span>'; |
|
269 | + $odtResult .= '<text:span text:style-name="subText">'.($tag['children'] != null ? $this->_replaceHtmlWithOdtTag($tag['children'], $customStyles, $fontDeclarations, $encode) : $this->encode_chars($tag['innerText'], $encode, $charset)).'</text:span>'; |
|
270 | 270 | break; |
271 | 271 | case 'sup': |
272 | - $odtResult .= '<text:span text:style-name="supText">' . ($tag['children'] != null ? $this->_replaceHtmlWithOdtTag($tag['children'], $customStyles, $fontDeclarations, $encode) : $this->encode_chars($tag['innerText'], $encode, $charset)) . '</text:span>'; |
|
272 | + $odtResult .= '<text:span text:style-name="supText">'.($tag['children'] != null ? $this->_replaceHtmlWithOdtTag($tag['children'], $customStyles, $fontDeclarations, $encode) : $this->encode_chars($tag['innerText'], $encode, $charset)).'</text:span>'; |
|
273 | 273 | break; |
274 | 274 | case 'span': |
275 | 275 | if (isset($tag['attributes']['style'])) { |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | if (!in_array($fontName, $fontDeclarations)) { |
285 | 285 | array_push($fontDeclarations, $fontName); |
286 | 286 | } |
287 | - $odtStyles .= '<style:text-properties style:font-name="' . $fontName . '" />'; |
|
287 | + $odtStyles .= '<style:text-properties style:font-name="'.$fontName.'" />'; |
|
288 | 288 | break; |
289 | 289 | case 'font-size': |
290 | 290 | if (preg_match('/([0-9]+)\s?(px|pt)/', $styleValue, $matches)) { |
@@ -292,21 +292,21 @@ discard block |
||
292 | 292 | if ($matches[2] == 'px') { |
293 | 293 | $fontSize = round($fontSize * 0.75); |
294 | 294 | } |
295 | - $odtStyles .= '<style:text-properties fo:font-size="' . $fontSize . 'pt" style:font-size-asian="' . $fontSize . 'pt" style:font-size-complex="' . $fontSize . 'pt" />'; |
|
295 | + $odtStyles .= '<style:text-properties fo:font-size="'.$fontSize.'pt" style:font-size-asian="'.$fontSize.'pt" style:font-size-complex="'.$fontSize.'pt" />'; |
|
296 | 296 | } |
297 | 297 | break; |
298 | 298 | case 'color': |
299 | 299 | if (preg_match('/#[0-9A-Fa-f]{3}(?:[0-9A-Fa-f]{3})?/', $styleValue)) { |
300 | - $odtStyles .= '<style:text-properties fo:color="' . $styleValue . '" />'; |
|
300 | + $odtStyles .= '<style:text-properties fo:color="'.$styleValue.'" />'; |
|
301 | 301 | } |
302 | 302 | break; |
303 | 303 | } |
304 | 304 | } |
305 | 305 | if (strlen($odtStyles) > 0) { |
306 | 306 | // Generate a unique id for the style (using microtime and random because some CPUs are really fast...) |
307 | - $key = str_replace('.', '', (string) microtime(true)) . uniqid(mt_rand()); |
|
307 | + $key = str_replace('.', '', (string) microtime(true)).uniqid(mt_rand()); |
|
308 | 308 | $customStyles[$key] = $odtStyles; |
309 | - $odtResult .= '<text:span text:style-name="customStyle' . $key . '">' . ($tag['children'] != null ? $this->_replaceHtmlWithOdtTag($tag['children'], $customStyles, $fontDeclarations, $encode) : $this->encode_chars($tag['innerText'], $encode, $charset)) . '</text:span>'; |
|
309 | + $odtResult .= '<text:span text:style-name="customStyle'.$key.'">'.($tag['children'] != null ? $this->_replaceHtmlWithOdtTag($tag['children'], $customStyles, $fontDeclarations, $encode) : $this->encode_chars($tag['innerText'], $encode, $charset)).'</text:span>'; |
|
310 | 310 | } |
311 | 311 | } |
312 | 312 | break; |
@@ -443,24 +443,24 @@ discard block |
||
443 | 443 | public function htmlToUTFAndPreOdf($value) |
444 | 444 | { |
445 | 445 | // We decode into utf8, entities |
446 | - $value=dol_html_entity_decode($value, ENT_QUOTES|ENT_HTML5); |
|
446 | + $value = dol_html_entity_decode($value, ENT_QUOTES | ENT_HTML5); |
|
447 | 447 | |
448 | 448 | // We convert html tags |
449 | - $ishtml=dol_textishtml($value); |
|
449 | + $ishtml = dol_textishtml($value); |
|
450 | 450 | if ($ishtml) { |
451 | 451 | // If string is "MYPODUCT - Desc <strong>bold</strong> with é accent<br />\n<br />\nUn texto en español ?" |
452 | 452 | // Result after clean must be "MYPODUCT - Desc bold with é accent\n\nUn texto en español ?" |
453 | 453 | |
454 | 454 | // We want to ignore \n and we want all <br> to be \n |
455 | - $value=preg_replace('/(\r\n|\r|\n)/i', '', $value); |
|
456 | - $value=preg_replace('/<br>/i', "\n", $value); |
|
457 | - $value=preg_replace('/<br\s+[^<>\/]*>/i', "\n", $value); |
|
458 | - $value=preg_replace('/<br\s+[^<>\/]*\/>/i', "\n", $value); |
|
455 | + $value = preg_replace('/(\r\n|\r|\n)/i', '', $value); |
|
456 | + $value = preg_replace('/<br>/i', "\n", $value); |
|
457 | + $value = preg_replace('/<br\s+[^<>\/]*>/i', "\n", $value); |
|
458 | + $value = preg_replace('/<br\s+[^<>\/]*\/>/i', "\n", $value); |
|
459 | 459 | |
460 | 460 | //$value=preg_replace('/<strong>/','__lt__text:p text:style-name=__quot__bold__quot____gt__',$value); |
461 | 461 | //$value=preg_replace('/<\/strong>/','__lt__/text:p__gt__',$value); |
462 | 462 | |
463 | - $value=dol_string_nohtmltag($value, 0); |
|
463 | + $value = dol_string_nohtmltag($value, 0); |
|
464 | 464 | } |
465 | 465 | |
466 | 466 | return $value; |
@@ -536,10 +536,10 @@ discard block |
||
536 | 536 | $balise = str_replace('row.', '', $matches2[1]); |
537 | 537 | // Move segment tags around the row |
538 | 538 | $replace = array( |
539 | - '[!-- BEGIN ' . $matches2[1] . ' --]' => '', |
|
540 | - '[!-- END ' . $matches2[1] . ' --]' => '', |
|
541 | - '<table:table-row' => '[!-- BEGIN ' . $balise . ' --]<table:table-row', |
|
542 | - '</table:table-row>' => '</table:table-row>[!-- END ' . $balise . ' --]' |
|
539 | + '[!-- BEGIN '.$matches2[1].' --]' => '', |
|
540 | + '[!-- END '.$matches2[1].' --]' => '', |
|
541 | + '<table:table-row' => '[!-- BEGIN '.$balise.' --]<table:table-row', |
|
542 | + '</table:table-row>' => '</table:table-row>[!-- END '.$balise.' --]' |
|
543 | 543 | ); |
544 | 544 | $replacedXML = str_replace(array_keys($replace), array_values($replace), $matches[0][$i]); |
545 | 545 | $this->contentXml = str_replace($matches[0][$i], $replacedXML, $this->contentXml); |
@@ -562,14 +562,14 @@ discard block |
||
562 | 562 | else return; |
563 | 563 | |
564 | 564 | // Search all tags found into condition to complete $this->vars, so we will proceed all tests even if not defined |
565 | - $reg='@\[!--\sIF\s([{}a-zA-Z0-9\.\,_]+)\s--\]@smU'; |
|
565 | + $reg = '@\[!--\sIF\s([{}a-zA-Z0-9\.\,_]+)\s--\]@smU'; |
|
566 | 566 | $matches = array(); |
567 | 567 | preg_match_all($reg, $xml, $matches, PREG_SET_ORDER); |
568 | 568 | |
569 | 569 | //var_dump($this->vars);exit; |
570 | 570 | foreach ($matches as $match) { // For each match, if there is no entry into this->vars, we add it |
571 | - if (! empty($match[1]) && ! isset($this->vars[$match[1]])) { |
|
572 | - $this->vars[$match[1]] = ''; // Not defined, so we set it to '', we just need entry into this->vars for next loop |
|
571 | + if (!empty($match[1]) && !isset($this->vars[$match[1]])) { |
|
572 | + $this->vars[$match[1]] = ''; // Not defined, so we set it to '', we just need entry into this->vars for next loop |
|
573 | 573 | } |
574 | 574 | } |
575 | 575 | //var_dump($this->vars);exit; |
@@ -584,7 +584,7 @@ discard block |
||
584 | 584 | // Remove the IF tag |
585 | 585 | $xml = str_replace('[!-- IF '.$key.' --]', '', $xml); |
586 | 586 | // Remove everything between the ELSE tag (if it exists) and the ENDIF tag |
587 | - $reg = '@(\[!--\sELSE\s' . $key . '\s--\](.*))?\[!--\sENDIF\s' . $key . '\s--\]@smU'; // U modifier = all quantifiers are non-greedy |
|
587 | + $reg = '@(\[!--\sELSE\s'.$key.'\s--\](.*))?\[!--\sENDIF\s'.$key.'\s--\]@smU'; // U modifier = all quantifiers are non-greedy |
|
588 | 588 | $xml = preg_replace($reg, '', $xml); |
589 | 589 | /*if ($sav != $xml) |
590 | 590 | { |
@@ -597,7 +597,7 @@ discard block |
||
597 | 597 | //dol_syslog("Var ".$key." is not defined, we remove the IF, ELSE and ENDIF "); |
598 | 598 | //$sav=$xml; |
599 | 599 | // Find all conditional blocks for this variable: from IF to ELSE and to ENDIF |
600 | - $reg = '@\[!--\sIF\s' . $key . '\s--\](.*)(\[!--\sELSE\s' . $key . '\s--\](.*))?\[!--\sENDIF\s' . $key . '\s--\]@smU'; // U modifier = all quantifiers are non-greedy |
|
600 | + $reg = '@\[!--\sIF\s'.$key.'\s--\](.*)(\[!--\sELSE\s'.$key.'\s--\](.*))?\[!--\sENDIF\s'.$key.'\s--\]@smU'; // U modifier = all quantifiers are non-greedy |
|
601 | 601 | preg_match_all($reg, $xml, $matches, PREG_SET_ORDER); |
602 | 602 | foreach ($matches as $match) { // For each match, if there is an ELSE clause, we replace the whole block by the value in the ELSE clause |
603 | 603 | if (!empty($match[3])) $xml = str_replace($match[0], $match[3], $xml); |
@@ -625,12 +625,12 @@ discard block |
||
625 | 625 | */ |
626 | 626 | public function mergeSegment(Segment $segment) |
627 | 627 | { |
628 | - if (! array_key_exists($segment->getName(), $this->segments)) { |
|
629 | - throw new OdfException($segment->getName() . 'cannot be parsed, has it been set yet ?'); |
|
628 | + if (!array_key_exists($segment->getName(), $this->segments)) { |
|
629 | + throw new OdfException($segment->getName().'cannot be parsed, has it been set yet ?'); |
|
630 | 630 | } |
631 | 631 | $string = $segment->getName(); |
632 | 632 | // $reg = '@<text:p[^>]*>\[!--\sBEGIN\s' . $string . '\s--\](.*)\[!--.+END\s' . $string . '\s--\]<\/text:p>@smU'; |
633 | - $reg = '@\[!--\sBEGIN\s' . $string . '\s--\](.*)\[!--.+END\s' . $string . '\s--\]@smU'; |
|
633 | + $reg = '@\[!--\sBEGIN\s'.$string.'\s--\](.*)\[!--.+END\s'.$string.'\s--\]@smU'; |
|
634 | 634 | $this->contentXml = preg_replace($reg, $segment->getXmlParsed(), $this->contentXml); |
635 | 635 | return $this; |
636 | 636 | } |
@@ -642,7 +642,7 @@ discard block |
||
642 | 642 | */ |
643 | 643 | public function printVars() |
644 | 644 | { |
645 | - return print_r('<pre>' . print_r($this->vars, true) . '</pre>', true); |
|
645 | + return print_r('<pre>'.print_r($this->vars, true).'</pre>', true); |
|
646 | 646 | } |
647 | 647 | |
648 | 648 | /** |
@@ -663,7 +663,7 @@ discard block |
||
663 | 663 | */ |
664 | 664 | public function printDeclaredSegments() |
665 | 665 | { |
666 | - return '<pre>' . print_r(implode(' ', array_keys($this->segments)), true) . '</pre>'; |
|
666 | + return '<pre>'.print_r(implode(' ', array_keys($this->segments)), true).'</pre>'; |
|
667 | 667 | } |
668 | 668 | |
669 | 669 | /** |
@@ -699,7 +699,7 @@ discard block |
||
699 | 699 | { |
700 | 700 | if ($file !== null && is_string($file)) { |
701 | 701 | if (file_exists($file) && !(is_file($file) && is_writable($file))) { |
702 | - throw new OdfException('Permission denied : can\'t create ' . $file); |
|
702 | + throw new OdfException('Permission denied : can\'t create '.$file); |
|
703 | 703 | } |
704 | 704 | $this->_save(); |
705 | 705 | copy($this->tmpfile, $file); |
@@ -716,7 +716,7 @@ discard block |
||
716 | 716 | */ |
717 | 717 | private function _save() |
718 | 718 | { |
719 | - $res=$this->file->open($this->tmpfile); // tmpfile is odt template |
|
719 | + $res = $this->file->open($this->tmpfile); // tmpfile is odt template |
|
720 | 720 | $this->_parse('content'); |
721 | 721 | $this->_parse('styles'); |
722 | 722 | $this->_parse('meta'); |
@@ -724,23 +724,23 @@ discard block |
||
724 | 724 | $this->setMetaData(); |
725 | 725 | //print $this->metaXml;exit; |
726 | 726 | |
727 | - if (! $this->file->addFromString('content.xml', $this->contentXml)) { |
|
727 | + if (!$this->file->addFromString('content.xml', $this->contentXml)) { |
|
728 | 728 | throw new OdfException('Error during file export addFromString content'); |
729 | 729 | } |
730 | - if (! $this->file->addFromString('meta.xml', $this->metaXml)) { |
|
730 | + if (!$this->file->addFromString('meta.xml', $this->metaXml)) { |
|
731 | 731 | throw new OdfException('Error during file export addFromString meta'); |
732 | 732 | } |
733 | - if (! $this->file->addFromString('styles.xml', $this->stylesXml)) { |
|
733 | + if (!$this->file->addFromString('styles.xml', $this->stylesXml)) { |
|
734 | 734 | throw new OdfException('Error during file export addFromString styles'); |
735 | 735 | } |
736 | 736 | |
737 | 737 | foreach ($this->images as $imageKey => $imageValue) { |
738 | 738 | // Add the image inside the ODT document |
739 | - $this->file->addFile($imageKey, 'Pictures/' . $imageValue); |
|
739 | + $this->file->addFile($imageKey, 'Pictures/'.$imageValue); |
|
740 | 740 | // Add the image to the Manifest (which maintains a list of images, necessary to avoid "Corrupt ODT file. Repair?" when opening the file with LibreOffice) |
741 | 741 | $this->addImageToManifest($imageValue); |
742 | 742 | } |
743 | - if (! $this->file->addFromString('./META-INF/manifest.xml', $this->manifestXml)) { |
|
743 | + if (!$this->file->addFromString('./META-INF/manifest.xml', $this->manifestXml)) { |
|
744 | 744 | throw new OdfException('Error during file export: manifest.xml'); |
745 | 745 | } |
746 | 746 | $this->file->close(); |
@@ -754,7 +754,7 @@ discard block |
||
754 | 754 | */ |
755 | 755 | public function setMetaData() |
756 | 756 | { |
757 | - if (empty($this->creator)) $this->creator=''; |
|
757 | + if (empty($this->creator)) $this->creator = ''; |
|
758 | 758 | |
759 | 759 | $this->metaXml = preg_replace('/<dc:date>.*<\/dc:date>/', '<dc:date>'.gmdate("Y-m-d\TH:i:s").'</dc:date>', $this->metaXml); |
760 | 760 | $this->metaXml = preg_replace('/<dc:creator>.*<\/dc:creator>/', '<dc:creator>'.htmlspecialchars($this->creator).'</dc:creator>', $this->metaXml); |
@@ -800,8 +800,8 @@ discard block |
||
800 | 800 | throw new OdfException("headers already sent ($filename at $linenum)"); |
801 | 801 | } |
802 | 802 | |
803 | - if ( $name == "" ) { |
|
804 | - $name = md5(uniqid()) . ".odt"; |
|
803 | + if ($name == "") { |
|
804 | + $name = md5(uniqid()).".odt"; |
|
805 | 805 | } |
806 | 806 | |
807 | 807 | header('Content-type: application/vnd.oasis.opendocument.text'); |
@@ -822,18 +822,18 @@ discard block |
||
822 | 822 | { |
823 | 823 | global $conf; |
824 | 824 | |
825 | - if ( $name == "" ) $name = "temp".md5(uniqid()); |
|
825 | + if ($name == "") $name = "temp".md5(uniqid()); |
|
826 | 826 | |
827 | 827 | dol_syslog(get_class($this).'::exportAsAttachedPDF $name='.$name, LOG_DEBUG); |
828 | 828 | $this->saveToDisk($name); |
829 | 829 | |
830 | - $execmethod=(empty($conf->global->MAIN_EXEC_USE_POPEN)?1:2); // 1 or 2 |
|
830 | + $execmethod = (empty($conf->global->MAIN_EXEC_USE_POPEN) ? 1 : 2); // 1 or 2 |
|
831 | 831 | // Method 1 sometimes hang the server. |
832 | 832 | |
833 | 833 | |
834 | 834 | // Export to PDF using LibreOffice |
835 | 835 | if (getDolGlobalString('MAIN_ODT_AS_PDF') == 'libreoffice') { |
836 | - dol_mkdir($conf->user->dir_temp); // We must be sure the directory exists and is writable |
|
836 | + dol_mkdir($conf->user->dir_temp); // We must be sure the directory exists and is writable |
|
837 | 837 | |
838 | 838 | // We delete and recreate a subdir because the soffice may have change pemrissions on it |
839 | 839 | dol_delete_dir_recursive($conf->user->dir_temp.'/odtaspdf'); |
@@ -843,7 +843,7 @@ discard block |
||
843 | 843 | // using windows libreoffice that must be in path |
844 | 844 | // using linux/mac libreoffice that must be in path |
845 | 845 | // Note PHP Config "fastcgi.impersonate=0" must set to 0 - Default is 1 |
846 | - $command ='soffice --headless -env:UserInstallation=file:\''.$conf->user->dir_temp.'/odtaspdf\' --convert-to pdf --outdir '. escapeshellarg(dirname($name)). " ".escapeshellarg($name); |
|
846 | + $command = 'soffice --headless -env:UserInstallation=file:\''.$conf->user->dir_temp.'/odtaspdf\' --convert-to pdf --outdir '.escapeshellarg(dirname($name))." ".escapeshellarg($name); |
|
847 | 847 | } elseif (preg_match('/unoconv/', getDolGlobalString('MAIN_ODT_AS_PDF'))) { |
848 | 848 | // If issue with unoconv, see https://github.com/dagwieers/unoconv/issues/87 |
849 | 849 | |
@@ -873,13 +873,13 @@ discard block |
||
873 | 873 | //$command = '/usr/bin/unoconv -vvv '.escapeshellcmd($name); |
874 | 874 | } else { |
875 | 875 | // deprecated old method using odt2pdf.sh (native, jodconverter, ...) |
876 | - $tmpname=preg_replace('/\.odt/i', '', $name); |
|
876 | + $tmpname = preg_replace('/\.odt/i', '', $name); |
|
877 | 877 | |
878 | 878 | if (getDolGlobalString('MAIN_DOL_SCRIPTS_ROOT')) { |
879 | - $command = getDolGlobalString('MAIN_DOL_SCRIPTS_ROOT').'/scripts/odt2pdf/odt2pdf.sh '.escapeshellcmd($tmpname).' '.(is_numeric(getDolGlobalString('MAIN_ODT_AS_PDF'))?'jodconverter':getDolGlobalString('MAIN_ODT_AS_PDF')); |
|
879 | + $command = getDolGlobalString('MAIN_DOL_SCRIPTS_ROOT').'/scripts/odt2pdf/odt2pdf.sh '.escapeshellcmd($tmpname).' '.(is_numeric(getDolGlobalString('MAIN_ODT_AS_PDF')) ? 'jodconverter' : getDolGlobalString('MAIN_ODT_AS_PDF')); |
|
880 | 880 | } else { |
881 | 881 | dol_syslog(get_class($this).'::exportAsAttachedPDF is used but the constant MAIN_DOL_SCRIPTS_ROOT with path to script directory was not defined.', LOG_WARNING); |
882 | - $command = '../../scripts/odt2pdf/odt2pdf.sh '.escapeshellcmd($tmpname).' '.(is_numeric(getDolGlobalString('MAIN_ODT_AS_PDF'))?'jodconverter':getDolGlobalString('MAIN_ODT_AS_PDF')); |
|
882 | + $command = '../../scripts/odt2pdf/odt2pdf.sh '.escapeshellcmd($tmpname).' '.(is_numeric(getDolGlobalString('MAIN_ODT_AS_PDF')) ? 'jodconverter' : getDolGlobalString('MAIN_ODT_AS_PDF')); |
|
883 | 883 | } |
884 | 884 | } |
885 | 885 | |
@@ -892,14 +892,14 @@ discard block |
||
892 | 892 | // $result = $utils->executeCLI($command, $outputfile); and replace test on $execmethod. |
893 | 893 | // $retval will be $result['result'] |
894 | 894 | // $errorstring will be $result['output'] |
895 | - $retval=0; $output_arr=array(); |
|
895 | + $retval = 0; $output_arr = array(); |
|
896 | 896 | if ($execmethod == 1) { |
897 | 897 | exec($command, $output_arr, $retval); |
898 | 898 | } |
899 | 899 | if ($execmethod == 2) { |
900 | 900 | $outputfile = DOL_DATA_ROOT.'/odt2pdf.log'; |
901 | 901 | |
902 | - $ok=0; |
|
902 | + $ok = 0; |
|
903 | 903 | $handle = fopen($outputfile, 'w'); |
904 | 904 | if ($handle) { |
905 | 905 | dol_syslog(get_class($this)."Run command ".$command, LOG_DEBUG); |
@@ -908,7 +908,7 @@ discard block |
||
908 | 908 | while (!feof($handlein)) { |
909 | 909 | $read = fgets($handlein); |
910 | 910 | fwrite($handle, $read); |
911 | - $output_arr[]=$read; |
|
911 | + $output_arr[] = $read; |
|
912 | 912 | } |
913 | 913 | pclose($handlein); |
914 | 914 | fclose($handle); |
@@ -918,7 +918,7 @@ discard block |
||
918 | 918 | |
919 | 919 | if ($retval == 0) { |
920 | 920 | dol_syslog(get_class($this).'::exportAsAttachedPDF $ret_val='.$retval, LOG_DEBUG); |
921 | - $filename=''; $linenum=0; |
|
921 | + $filename = ''; $linenum = 0; |
|
922 | 922 | |
923 | 923 | if (php_sapi_name() != 'cli') { // If we are in a web context (not into CLI context) |
924 | 924 | if (headers_sent($filename, $linenum)) { |
@@ -926,7 +926,7 @@ discard block |
||
926 | 926 | } |
927 | 927 | |
928 | 928 | if (!empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { |
929 | - $name=preg_replace('/\.od(x|t)/i', '', $name); |
|
929 | + $name = preg_replace('/\.od(x|t)/i', '', $name); |
|
930 | 930 | header('Content-type: application/pdf'); |
931 | 931 | header('Content-Disposition: attachment; filename="'.$name.'.pdf"'); |
932 | 932 | readfile($name.".pdf"); |
@@ -941,13 +941,13 @@ discard block |
||
941 | 941 | dol_syslog(get_class($this).'::exportAsAttachedPDF $output_arr='.var_export($output_arr, true), LOG_DEBUG); |
942 | 942 | |
943 | 943 | if ($retval == 126) { |
944 | - throw new OdfException('Permission execute convert script : ' . $command); |
|
944 | + throw new OdfException('Permission execute convert script : '.$command); |
|
945 | 945 | } else { |
946 | - $errorstring=''; |
|
946 | + $errorstring = ''; |
|
947 | 947 | foreach ($output_arr as $line) { |
948 | - $errorstring.= $line."<br>"; |
|
948 | + $errorstring .= $line."<br>"; |
|
949 | 949 | } |
950 | - throw new OdfException('ODT to PDF convert fail (option MAIN_ODT_AS_PDF is '.$conf->global->MAIN_ODT_AS_PDF.', command was '.$command.', retval='.$retval.') : ' . $errorstring); |
|
950 | + throw new OdfException('ODT to PDF convert fail (option MAIN_ODT_AS_PDF is '.$conf->global->MAIN_ODT_AS_PDF.', command was '.$command.', retval='.$retval.') : '.$errorstring); |
|
951 | 951 | } |
952 | 952 | } |
953 | 953 | } |
@@ -1001,11 +1001,11 @@ discard block |
||
1001 | 1001 | if ($handle = opendir($dir)) { |
1002 | 1002 | while (($file = readdir($handle)) !== false) { |
1003 | 1003 | if ($file != '.' && $file != '..') { |
1004 | - if (is_dir($dir . '/' . $file)) { |
|
1005 | - $this->_rrmdir($dir . '/' . $file); |
|
1006 | - rmdir($dir . '/' . $file); |
|
1004 | + if (is_dir($dir.'/'.$file)) { |
|
1005 | + $this->_rrmdir($dir.'/'.$file); |
|
1006 | + rmdir($dir.'/'.$file); |
|
1007 | 1007 | } else { |
1008 | - unlink($dir . '/' . $file); |
|
1008 | + unlink($dir.'/'.$file); |
|
1009 | 1009 | } |
1010 | 1010 | } |
1011 | 1011 | } |
@@ -1021,7 +1021,7 @@ discard block |
||
1021 | 1021 | */ |
1022 | 1022 | public function getvalue($valuename) |
1023 | 1023 | { |
1024 | - $searchreg="/\\[".$valuename."\\](.*)\\[\\/".$valuename."\\]/"; |
|
1024 | + $searchreg = "/\\[".$valuename."\\](.*)\\[\\/".$valuename."\\]/"; |
|
1025 | 1025 | $matches = array(); |
1026 | 1026 | preg_match($searchreg, $this->contentXml, $matches); |
1027 | 1027 | $this->contentXml = preg_replace($searchreg, "", $this->contentXml); |
@@ -78,7 +78,10 @@ discard block |
||
78 | 78 | } |
79 | 79 | |
80 | 80 | $md5uniqid = md5(uniqid()); |
81 | - if ($this->config['PATH_TO_TMP']) $this->tmpdir = preg_replace('|[\/]$|', '', $this->config['PATH_TO_TMP']); // Remove last \ or / |
|
81 | + if ($this->config['PATH_TO_TMP']) { |
|
82 | + $this->tmpdir = preg_replace('|[\/]$|', '', $this->config['PATH_TO_TMP']); |
|
83 | + } |
|
84 | + // Remove last \ or / |
|
82 | 85 | $this->tmpdir .= ($this->tmpdir?'/':'').$md5uniqid; |
83 | 86 | $this->tmpfile = $this->tmpdir.'/'.$md5uniqid.'.odt'; // We keep .odt extension to allow OpenOffice usage during debug. |
84 | 87 | |
@@ -94,7 +97,9 @@ discard block |
||
94 | 97 | |
95 | 98 | // Load zip proxy |
96 | 99 | $zipHandler = $this->config['ZIP_PROXY']; |
97 | - if (!defined('PCLZIP_TEMPORARY_DIR')) define('PCLZIP_TEMPORARY_DIR', $this->tmpdir); |
|
100 | + if (!defined('PCLZIP_TEMPORARY_DIR')) { |
|
101 | + define('PCLZIP_TEMPORARY_DIR', $this->tmpdir); |
|
102 | + } |
|
98 | 103 | include_once 'zip/'.$zipHandler.'.php'; |
99 | 104 | if (! class_exists($this->config['ZIP_PROXY'])) { |
100 | 105 | throw new OdfException($this->config['ZIP_PROXY'] . ' class not found - check your php settings'); |
@@ -236,8 +241,12 @@ discard block |
||
236 | 241 | */ |
237 | 242 | private function _replaceHtmlWithOdtTag($tags, &$customStyles, &$fontDeclarations, $encode = false, $charset = '') |
238 | 243 | { |
239 | - if ($customStyles == null) $customStyles = array(); |
|
240 | - if ($fontDeclarations == null) $fontDeclarations = array(); |
|
244 | + if ($customStyles == null) { |
|
245 | + $customStyles = array(); |
|
246 | + } |
|
247 | + if ($fontDeclarations == null) { |
|
248 | + $fontDeclarations = array(); |
|
249 | + } |
|
241 | 250 | |
242 | 251 | $odtResult = ''; |
243 | 252 | |
@@ -556,10 +565,15 @@ discard block |
||
556 | 565 | */ |
557 | 566 | private function _parse($type = 'content') |
558 | 567 | { |
559 | - if ($type == 'content') $xml = &$this->contentXml; |
|
560 | - elseif ($type == 'styles') $xml = &$this->stylesXml; |
|
561 | - elseif ($type == 'meta') $xml = &$this->metaXml; |
|
562 | - else return; |
|
568 | + if ($type == 'content') { |
|
569 | + $xml = &$this->contentXml; |
|
570 | + } elseif ($type == 'styles') { |
|
571 | + $xml = &$this->stylesXml; |
|
572 | + } elseif ($type == 'meta') { |
|
573 | + $xml = &$this->metaXml; |
|
574 | + } else { |
|
575 | + return; |
|
576 | + } |
|
563 | 577 | |
564 | 578 | // Search all tags found into condition to complete $this->vars, so we will proceed all tests even if not defined |
565 | 579 | $reg='@\[!--\sIF\s([{}a-zA-Z0-9\.\,_]+)\s--\]@smU'; |
@@ -600,7 +614,9 @@ discard block |
||
600 | 614 | $reg = '@\[!--\sIF\s' . $key . '\s--\](.*)(\[!--\sELSE\s' . $key . '\s--\](.*))?\[!--\sENDIF\s' . $key . '\s--\]@smU'; // U modifier = all quantifiers are non-greedy |
601 | 615 | preg_match_all($reg, $xml, $matches, PREG_SET_ORDER); |
602 | 616 | foreach ($matches as $match) { // For each match, if there is an ELSE clause, we replace the whole block by the value in the ELSE clause |
603 | - if (!empty($match[3])) $xml = str_replace($match[0], $match[3], $xml); |
|
617 | + if (!empty($match[3])) { |
|
618 | + $xml = str_replace($match[0], $match[3], $xml); |
|
619 | + } |
|
604 | 620 | } |
605 | 621 | // Cleanup the other conditional blocks (all the others where there were no ELSE clause, we can just remove them altogether) |
606 | 622 | $xml = preg_replace($reg, '', $xml); |
@@ -754,7 +770,9 @@ discard block |
||
754 | 770 | */ |
755 | 771 | public function setMetaData() |
756 | 772 | { |
757 | - if (empty($this->creator)) $this->creator=''; |
|
773 | + if (empty($this->creator)) { |
|
774 | + $this->creator=''; |
|
775 | + } |
|
758 | 776 | |
759 | 777 | $this->metaXml = preg_replace('/<dc:date>.*<\/dc:date>/', '<dc:date>'.gmdate("Y-m-d\TH:i:s").'</dc:date>', $this->metaXml); |
760 | 778 | $this->metaXml = preg_replace('/<dc:creator>.*<\/dc:creator>/', '<dc:creator>'.htmlspecialchars($this->creator).'</dc:creator>', $this->metaXml); |
@@ -822,7 +840,9 @@ discard block |
||
822 | 840 | { |
823 | 841 | global $conf; |
824 | 842 | |
825 | - if ( $name == "" ) $name = "temp".md5(uniqid()); |
|
843 | + if ( $name == "" ) { |
|
844 | + $name = "temp".md5(uniqid()); |
|
845 | + } |
|
826 | 846 | |
827 | 847 | dol_syslog(get_class($this).'::exportAsAttachedPDF $name='.$name, LOG_DEBUG); |
828 | 848 | $this->saveToDisk($name); |
@@ -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 |
@@ -44,7 +44,7 @@ |
||
44 | 44 | } |
45 | 45 | public function next() |
46 | 46 | { |
47 | - $this->key ++; |
|
47 | + $this->key++; |
|
48 | 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'; |
@@ -88,21 +88,21 @@ discard block |
||
88 | 88 | { |
89 | 89 | // To provide debug information on line number processed |
90 | 90 | global $count; |
91 | - if (empty($count)) $count=1; |
|
91 | + if (empty($count)) $count = 1; |
|
92 | 92 | else $count++; |
93 | 93 | |
94 | - if (empty($this->savxml)) $this->savxml = $this->xml; // Sav content of line at first line merged, so we will reuse original for next steps |
|
94 | + if (empty($this->savxml)) $this->savxml = $this->xml; // Sav content of line at first line merged, so we will reuse original for next steps |
|
95 | 95 | $this->xml = $this->savxml; |
96 | - $tmpvars = $this->vars; // Store into $tmpvars so we won't modify this->vars when completing data with empty values |
|
96 | + $tmpvars = $this->vars; // Store into $tmpvars so we won't modify this->vars when completing data with empty values |
|
97 | 97 | |
98 | 98 | // Search all tags fou into condition to complete $tmpvars, so we will proceed all tests even if not defined |
99 | - $reg='@\[!--\sIF\s([{}a-zA-Z0-9\.\,_]+)\s--\]@smU'; |
|
99 | + $reg = '@\[!--\sIF\s([{}a-zA-Z0-9\.\,_]+)\s--\]@smU'; |
|
100 | 100 | $matches = array(); |
101 | 101 | preg_match_all($reg, $this->xml, $matches, PREG_SET_ORDER); |
102 | 102 | //var_dump($tmpvars);exit; |
103 | 103 | foreach ($matches as $match) { // For each match, if there is no entry into this->vars, we add it |
104 | - if (! empty($match[1]) && ! isset($tmpvars[$match[1]])) { |
|
105 | - $tmpvars[$match[1]] = ''; // Not defined, so we set it to '', we just need entry into this->vars for next loop |
|
104 | + if (!empty($match[1]) && !isset($tmpvars[$match[1]])) { |
|
105 | + $tmpvars[$match[1]] = ''; // Not defined, so we set it to '', we just need entry into this->vars for next loop |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | |
@@ -114,13 +114,13 @@ discard block |
||
114 | 114 | // Remove the IF tag |
115 | 115 | $this->xml = str_replace('[!-- IF '.$key.' --]', '', $this->xml); |
116 | 116 | // Remove everything between the ELSE tag (if it exists) and the ENDIF tag |
117 | - $reg = '@(\[!--\sELSE\s' . $key . '\s--\](.*))?\[!--\sENDIF\s' . $key . '\s--\]@smU'; // U modifier = all quantifiers are non-greedy |
|
117 | + $reg = '@(\[!--\sELSE\s'.$key.'\s--\](.*))?\[!--\sENDIF\s'.$key.'\s--\]@smU'; // U modifier = all quantifiers are non-greedy |
|
118 | 118 | $this->xml = preg_replace($reg, '', $this->xml); |
119 | 119 | } |
120 | 120 | // Else the value is false, then two cases: no ELSE and we're done, or there is at least one place where there is an ELSE clause, then we replace it |
121 | 121 | else { |
122 | 122 | // Find all conditional blocks for this variable: from IF to ELSE and to ENDIF |
123 | - $reg = '@\[!--\sIF\s' . $key . '\s--\](.*)(\[!--\sELSE\s' . $key . '\s--\](.*))?\[!--\sENDIF\s' . $key . '\s--\]@smU'; // U modifier = all quantifiers are non-greedy |
|
123 | + $reg = '@\[!--\sIF\s'.$key.'\s--\](.*)(\[!--\sELSE\s'.$key.'\s--\](.*))?\[!--\sENDIF\s'.$key.'\s--\]@smU'; // U modifier = all quantifiers are non-greedy |
|
124 | 124 | preg_match_all($reg, $this->xml, $matches, PREG_SET_ORDER); |
125 | 125 | foreach ($matches as $match) { // For each match, if there is an ELSE clause, we replace the whole block by the value in the ELSE clause |
126 | 126 | if (!empty($match[3])) $this->xml = str_replace($match[0], $match[3], $this->xml); |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | $this->xmlParsed .= str_replace(array_keys($tmpvars), array_values($tmpvars), $this->xml); |
134 | 134 | if ($this->hasChildren()) { |
135 | 135 | foreach ($this->children as $child) { |
136 | - $this->xmlParsed = str_replace($child->xml, ($child->xmlParsed=="")?$child->merge():$child->xmlParsed, $this->xmlParsed); |
|
136 | + $this->xmlParsed = str_replace($child->xml, ($child->xmlParsed == "") ? $child->merge() : $child->xmlParsed, $this->xmlParsed); |
|
137 | 137 | $child->xmlParsed = ''; |
138 | 138 | } |
139 | 139 | } |
@@ -143,9 +143,9 @@ discard block |
||
143 | 143 | $this->xmlParsed = $this->macroReplace($this->xmlParsed); |
144 | 144 | $this->file->open($this->odf->getTmpfile()); |
145 | 145 | foreach ($this->images as $imageKey => $imageValue) { |
146 | - if ($this->file->getFromName('Pictures/' . $imageValue) === false) { |
|
146 | + if ($this->file->getFromName('Pictures/'.$imageValue) === false) { |
|
147 | 147 | // Add the image inside the ODT document |
148 | - $this->file->addFile($imageKey, 'Pictures/' . $imageValue); |
|
148 | + $this->file->addFile($imageKey, 'Pictures/'.$imageValue); |
|
149 | 149 | // Add the image to the Manifest (which maintains a list of images, necessary to avoid "Corrupt ODT file. Repair?" when opening the file with LibreOffice) |
150 | 150 | $this->odf->addImageToManifest($imageValue); |
151 | 151 | } |
@@ -176,16 +176,16 @@ discard block |
||
176 | 176 | $dateinonemontharray = dol_get_next_month($hoy['mon'], $hoy['year']); |
177 | 177 | $nextMonth = $dateinonemontharray['month']; |
178 | 178 | |
179 | - $patterns=array( '/__CURRENTDAY__/u','/__CURENTWEEKDAY__/u', |
|
180 | - '/__CURRENTMONTH__/u','/__CURRENTMONTHLONG__/u', |
|
181 | - '/__NEXTMONTH__/u','/__NEXTMONTHLONG__/u', |
|
182 | - '/__CURRENTYEAR__/u','/__NEXTYEAR__/u' ); |
|
183 | - $values=array( $hoy['mday'], $langs->transnoentitiesnoconv($hoy['wday']), |
|
179 | + $patterns = array('/__CURRENTDAY__/u', '/__CURENTWEEKDAY__/u', |
|
180 | + '/__CURRENTMONTH__/u', '/__CURRENTMONTHLONG__/u', |
|
181 | + '/__NEXTMONTH__/u', '/__NEXTMONTHLONG__/u', |
|
182 | + '/__CURRENTYEAR__/u', '/__NEXTYEAR__/u'); |
|
183 | + $values = array($hoy['mday'], $langs->transnoentitiesnoconv($hoy['wday']), |
|
184 | 184 | $hoy['mon'], monthArray($langs)[$hoy['mon']], |
185 | 185 | $nextMonth, monthArray($langs)[$nextMonth], |
186 | - $hoy['year'], $hoy['year']+1 ); |
|
186 | + $hoy['year'], $hoy['year'] + 1); |
|
187 | 187 | |
188 | - $text=preg_replace($patterns, $values, $text); |
|
188 | + $text = preg_replace($patterns, $values, $text); |
|
189 | 189 | |
190 | 190 | return $text; |
191 | 191 | } |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | */ |
224 | 224 | public function setVars($key, $value, $encode = true, $charset = 'ISO-8859') |
225 | 225 | { |
226 | - $tag = $this->odf->getConfig('DELIMITER_LEFT') . $key . $this->odf->getConfig('DELIMITER_RIGHT'); |
|
226 | + $tag = $this->odf->getConfig('DELIMITER_LEFT').$key.$this->odf->getConfig('DELIMITER_RIGHT'); |
|
227 | 227 | |
228 | 228 | if (strpos($this->xml, $tag) === false) { |
229 | 229 | //throw new SegmentException("var $key not found in {$this->getName()}"); |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | if (array_key_exists($prop, $this->children)) { |
278 | 278 | return $this->children[$prop]; |
279 | 279 | } else { |
280 | - throw new SegmentException('child ' . $prop . ' does not exist'); |
|
280 | + throw new SegmentException('child '.$prop.' does not exist'); |
|
281 | 281 | } |
282 | 282 | } |
283 | 283 | /** |
@@ -88,10 +88,16 @@ discard block |
||
88 | 88 | { |
89 | 89 | // To provide debug information on line number processed |
90 | 90 | global $count; |
91 | - if (empty($count)) $count=1; |
|
92 | - else $count++; |
|
91 | + if (empty($count)) { |
|
92 | + $count=1; |
|
93 | + } else { |
|
94 | + $count++; |
|
95 | + } |
|
93 | 96 | |
94 | - if (empty($this->savxml)) $this->savxml = $this->xml; // Sav content of line at first line merged, so we will reuse original for next steps |
|
97 | + if (empty($this->savxml)) { |
|
98 | + $this->savxml = $this->xml; |
|
99 | + } |
|
100 | + // Sav content of line at first line merged, so we will reuse original for next steps |
|
95 | 101 | $this->xml = $this->savxml; |
96 | 102 | $tmpvars = $this->vars; // Store into $tmpvars so we won't modify this->vars when completing data with empty values |
97 | 103 | |
@@ -123,7 +129,9 @@ discard block |
||
123 | 129 | $reg = '@\[!--\sIF\s' . $key . '\s--\](.*)(\[!--\sELSE\s' . $key . '\s--\](.*))?\[!--\sENDIF\s' . $key . '\s--\]@smU'; // U modifier = all quantifiers are non-greedy |
124 | 130 | preg_match_all($reg, $this->xml, $matches, PREG_SET_ORDER); |
125 | 131 | foreach ($matches as $match) { // For each match, if there is an ELSE clause, we replace the whole block by the value in the ELSE clause |
126 | - if (!empty($match[3])) $this->xml = str_replace($match[0], $match[3], $this->xml); |
|
132 | + if (!empty($match[3])) { |
|
133 | + $this->xml = str_replace($match[0], $match[3], $this->xml); |
|
134 | + } |
|
127 | 135 | } |
128 | 136 | // Cleanup the other conditional blocks (all the others where there were no ELSE clause, we can just remove them altogether) |
129 | 137 | $this->xml = preg_replace($reg, '', $this->xml); |
@@ -260,7 +260,7 @@ |
||
260 | 260 | |
261 | 261 | $xml = <<<IMG |
262 | 262 | <draw:frame draw:style-name="fr1" draw:name="$filename" text:anchor-type="aschar" svg:width="{$width}cm" svg:height="{$height}cm" draw:z-index="3"><draw:image xlink:href="Pictures/$file" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/></draw:frame> |
263 | -IMG; |
|
263 | +img; |
|
264 | 264 | $this->images[$value] = $file; |
265 | 265 | $this->setVars($key, $xml, false); |
266 | 266 | return $this; |
@@ -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(); |
@@ -1,23 +1,23 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | Swift_DependencyContainer::getInstance() |
4 | - ->register('cache') |
|
5 | - ->asAliasOf('cache.array') |
|
4 | + ->register('cache') |
|
5 | + ->asAliasOf('cache.array') |
|
6 | 6 | |
7 | - ->register('tempdir') |
|
8 | - ->asValue('/tmp') |
|
7 | + ->register('tempdir') |
|
8 | + ->asValue('/tmp') |
|
9 | 9 | |
10 | - ->register('cache.null') |
|
11 | - ->asSharedInstanceOf('Swift_KeyCache_NullKeyCache') |
|
10 | + ->register('cache.null') |
|
11 | + ->asSharedInstanceOf('Swift_KeyCache_NullKeyCache') |
|
12 | 12 | |
13 | - ->register('cache.array') |
|
14 | - ->asSharedInstanceOf('Swift_KeyCache_ArrayKeyCache') |
|
15 | - ->withDependencies(['cache.inputstream']) |
|
13 | + ->register('cache.array') |
|
14 | + ->asSharedInstanceOf('Swift_KeyCache_ArrayKeyCache') |
|
15 | + ->withDependencies(['cache.inputstream']) |
|
16 | 16 | |
17 | - ->register('cache.disk') |
|
18 | - ->asSharedInstanceOf('Swift_KeyCache_DiskKeyCache') |
|
19 | - ->withDependencies(['cache.inputstream', 'tempdir']) |
|
17 | + ->register('cache.disk') |
|
18 | + ->asSharedInstanceOf('Swift_KeyCache_DiskKeyCache') |
|
19 | + ->withDependencies(['cache.inputstream', 'tempdir']) |
|
20 | 20 | |
21 | - ->register('cache.inputstream') |
|
22 | - ->asNewInstanceOf('Swift_KeyCache_SimpleKeyCacheInputStream') |
|
21 | + ->register('cache.inputstream') |
|
22 | + ->asNewInstanceOf('Swift_KeyCache_SimpleKeyCacheInputStream') |
|
23 | 23 | ; |
@@ -3,132 +3,132 @@ |
||
3 | 3 | require __DIR__.'/../mime_types.php'; |
4 | 4 | |
5 | 5 | Swift_DependencyContainer::getInstance() |
6 | - ->register('properties.charset') |
|
7 | - ->asValue('utf-8') |
|
8 | - |
|
9 | - ->register('email.validator') |
|
10 | - ->asSharedInstanceOf('Egulias\EmailValidator\EmailValidator') |
|
11 | - |
|
12 | - ->register('mime.idgenerator.idright') |
|
13 | - // As SERVER_NAME can come from the user in certain configurations, check that |
|
14 | - // it does not contain forbidden characters (see RFC 952 and RFC 2181). Use |
|
15 | - // preg_replace() instead of preg_match() to prevent DoS attacks with long host names. |
|
16 | - ->asValue(!empty($_SERVER['SERVER_NAME']) && '' === preg_replace('/(?:^\[)?[a-zA-Z0-9-:\]_]+\.?/', '', $_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'swift.generated') |
|
17 | - |
|
18 | - ->register('mime.idgenerator') |
|
19 | - ->asSharedInstanceOf('Swift_Mime_IdGenerator') |
|
20 | - ->withDependencies([ |
|
21 | - 'mime.idgenerator.idright', |
|
22 | - ]) |
|
23 | - |
|
24 | - ->register('mime.message') |
|
25 | - ->asNewInstanceOf('Swift_Mime_SimpleMessage') |
|
26 | - ->withDependencies([ |
|
27 | - 'mime.headerset', |
|
28 | - 'mime.textcontentencoder', |
|
29 | - 'cache', |
|
30 | - 'mime.idgenerator', |
|
31 | - 'properties.charset', |
|
32 | - ]) |
|
33 | - |
|
34 | - ->register('mime.part') |
|
35 | - ->asNewInstanceOf('Swift_Mime_MimePart') |
|
36 | - ->withDependencies([ |
|
37 | - 'mime.headerset', |
|
38 | - 'mime.textcontentencoder', |
|
39 | - 'cache', |
|
40 | - 'mime.idgenerator', |
|
41 | - 'properties.charset', |
|
42 | - ]) |
|
43 | - |
|
44 | - ->register('mime.attachment') |
|
45 | - ->asNewInstanceOf('Swift_Mime_Attachment') |
|
46 | - ->withDependencies([ |
|
47 | - 'mime.headerset', |
|
48 | - 'mime.base64contentencoder', |
|
49 | - 'cache', |
|
50 | - 'mime.idgenerator', |
|
51 | - ]) |
|
52 | - ->addConstructorValue($swift_mime_types) |
|
53 | - |
|
54 | - ->register('mime.embeddedfile') |
|
55 | - ->asNewInstanceOf('Swift_Mime_EmbeddedFile') |
|
56 | - ->withDependencies([ |
|
57 | - 'mime.headerset', |
|
58 | - 'mime.base64contentencoder', |
|
59 | - 'cache', |
|
60 | - 'mime.idgenerator', |
|
61 | - ]) |
|
62 | - ->addConstructorValue($swift_mime_types) |
|
63 | - |
|
64 | - ->register('mime.headerfactory') |
|
65 | - ->asNewInstanceOf('Swift_Mime_SimpleHeaderFactory') |
|
66 | - ->withDependencies([ |
|
67 | - 'mime.qpheaderencoder', |
|
68 | - 'mime.rfc2231encoder', |
|
69 | - 'email.validator', |
|
70 | - 'properties.charset', |
|
71 | - 'address.idnaddressencoder', |
|
72 | - ]) |
|
73 | - |
|
74 | - ->register('mime.headerset') |
|
75 | - ->asNewInstanceOf('Swift_Mime_SimpleHeaderSet') |
|
76 | - ->withDependencies(['mime.headerfactory', 'properties.charset']) |
|
77 | - |
|
78 | - ->register('mime.qpheaderencoder') |
|
79 | - ->asNewInstanceOf('Swift_Mime_HeaderEncoder_QpHeaderEncoder') |
|
80 | - ->withDependencies(['mime.charstream']) |
|
81 | - |
|
82 | - ->register('mime.base64headerencoder') |
|
83 | - ->asNewInstanceOf('Swift_Mime_HeaderEncoder_Base64HeaderEncoder') |
|
84 | - ->withDependencies(['mime.charstream']) |
|
85 | - |
|
86 | - ->register('mime.charstream') |
|
87 | - ->asNewInstanceOf('Swift_CharacterStream_NgCharacterStream') |
|
88 | - ->withDependencies(['mime.characterreaderfactory', 'properties.charset']) |
|
89 | - |
|
90 | - ->register('mime.bytecanonicalizer') |
|
91 | - ->asSharedInstanceOf('Swift_StreamFilters_ByteArrayReplacementFilter') |
|
92 | - ->addConstructorValue([[0x0D, 0x0A], [0x0D], [0x0A]]) |
|
93 | - ->addConstructorValue([[0x0A], [0x0A], [0x0D, 0x0A]]) |
|
94 | - |
|
95 | - ->register('mime.characterreaderfactory') |
|
96 | - ->asSharedInstanceOf('Swift_CharacterReaderFactory_SimpleCharacterReaderFactory') |
|
97 | - |
|
98 | - ->register('mime.textcontentencoder') |
|
99 | - ->asAliasOf('mime.qpcontentencoder') |
|
100 | - |
|
101 | - ->register('mime.safeqpcontentencoder') |
|
102 | - ->asNewInstanceOf('Swift_Mime_ContentEncoder_QpContentEncoder') |
|
103 | - ->withDependencies(['mime.charstream', 'mime.bytecanonicalizer']) |
|
104 | - |
|
105 | - ->register('mime.rawcontentencoder') |
|
106 | - ->asNewInstanceOf('Swift_Mime_ContentEncoder_RawContentEncoder') |
|
107 | - |
|
108 | - ->register('mime.nativeqpcontentencoder') |
|
109 | - ->withDependencies(['properties.charset']) |
|
110 | - ->asNewInstanceOf('Swift_Mime_ContentEncoder_NativeQpContentEncoder') |
|
111 | - |
|
112 | - ->register('mime.qpcontentencoder') |
|
113 | - ->asNewInstanceOf('Swift_Mime_ContentEncoder_QpContentEncoderProxy') |
|
114 | - ->withDependencies(['mime.safeqpcontentencoder', 'mime.nativeqpcontentencoder', 'properties.charset']) |
|
115 | - |
|
116 | - ->register('mime.7bitcontentencoder') |
|
117 | - ->asNewInstanceOf('Swift_Mime_ContentEncoder_PlainContentEncoder') |
|
118 | - ->addConstructorValue('7bit') |
|
119 | - ->addConstructorValue(true) |
|
120 | - |
|
121 | - ->register('mime.8bitcontentencoder') |
|
122 | - ->asNewInstanceOf('Swift_Mime_ContentEncoder_PlainContentEncoder') |
|
123 | - ->addConstructorValue('8bit') |
|
124 | - ->addConstructorValue(true) |
|
125 | - |
|
126 | - ->register('mime.base64contentencoder') |
|
127 | - ->asSharedInstanceOf('Swift_Mime_ContentEncoder_Base64ContentEncoder') |
|
128 | - |
|
129 | - ->register('mime.rfc2231encoder') |
|
130 | - ->asNewInstanceOf('Swift_Encoder_Rfc2231Encoder') |
|
131 | - ->withDependencies(['mime.charstream']) |
|
6 | + ->register('properties.charset') |
|
7 | + ->asValue('utf-8') |
|
8 | + |
|
9 | + ->register('email.validator') |
|
10 | + ->asSharedInstanceOf('Egulias\EmailValidator\EmailValidator') |
|
11 | + |
|
12 | + ->register('mime.idgenerator.idright') |
|
13 | + // As SERVER_NAME can come from the user in certain configurations, check that |
|
14 | + // it does not contain forbidden characters (see RFC 952 and RFC 2181). Use |
|
15 | + // preg_replace() instead of preg_match() to prevent DoS attacks with long host names. |
|
16 | + ->asValue(!empty($_SERVER['SERVER_NAME']) && '' === preg_replace('/(?:^\[)?[a-zA-Z0-9-:\]_]+\.?/', '', $_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'swift.generated') |
|
17 | + |
|
18 | + ->register('mime.idgenerator') |
|
19 | + ->asSharedInstanceOf('Swift_Mime_IdGenerator') |
|
20 | + ->withDependencies([ |
|
21 | + 'mime.idgenerator.idright', |
|
22 | + ]) |
|
23 | + |
|
24 | + ->register('mime.message') |
|
25 | + ->asNewInstanceOf('Swift_Mime_SimpleMessage') |
|
26 | + ->withDependencies([ |
|
27 | + 'mime.headerset', |
|
28 | + 'mime.textcontentencoder', |
|
29 | + 'cache', |
|
30 | + 'mime.idgenerator', |
|
31 | + 'properties.charset', |
|
32 | + ]) |
|
33 | + |
|
34 | + ->register('mime.part') |
|
35 | + ->asNewInstanceOf('Swift_Mime_MimePart') |
|
36 | + ->withDependencies([ |
|
37 | + 'mime.headerset', |
|
38 | + 'mime.textcontentencoder', |
|
39 | + 'cache', |
|
40 | + 'mime.idgenerator', |
|
41 | + 'properties.charset', |
|
42 | + ]) |
|
43 | + |
|
44 | + ->register('mime.attachment') |
|
45 | + ->asNewInstanceOf('Swift_Mime_Attachment') |
|
46 | + ->withDependencies([ |
|
47 | + 'mime.headerset', |
|
48 | + 'mime.base64contentencoder', |
|
49 | + 'cache', |
|
50 | + 'mime.idgenerator', |
|
51 | + ]) |
|
52 | + ->addConstructorValue($swift_mime_types) |
|
53 | + |
|
54 | + ->register('mime.embeddedfile') |
|
55 | + ->asNewInstanceOf('Swift_Mime_EmbeddedFile') |
|
56 | + ->withDependencies([ |
|
57 | + 'mime.headerset', |
|
58 | + 'mime.base64contentencoder', |
|
59 | + 'cache', |
|
60 | + 'mime.idgenerator', |
|
61 | + ]) |
|
62 | + ->addConstructorValue($swift_mime_types) |
|
63 | + |
|
64 | + ->register('mime.headerfactory') |
|
65 | + ->asNewInstanceOf('Swift_Mime_SimpleHeaderFactory') |
|
66 | + ->withDependencies([ |
|
67 | + 'mime.qpheaderencoder', |
|
68 | + 'mime.rfc2231encoder', |
|
69 | + 'email.validator', |
|
70 | + 'properties.charset', |
|
71 | + 'address.idnaddressencoder', |
|
72 | + ]) |
|
73 | + |
|
74 | + ->register('mime.headerset') |
|
75 | + ->asNewInstanceOf('Swift_Mime_SimpleHeaderSet') |
|
76 | + ->withDependencies(['mime.headerfactory', 'properties.charset']) |
|
77 | + |
|
78 | + ->register('mime.qpheaderencoder') |
|
79 | + ->asNewInstanceOf('Swift_Mime_HeaderEncoder_QpHeaderEncoder') |
|
80 | + ->withDependencies(['mime.charstream']) |
|
81 | + |
|
82 | + ->register('mime.base64headerencoder') |
|
83 | + ->asNewInstanceOf('Swift_Mime_HeaderEncoder_Base64HeaderEncoder') |
|
84 | + ->withDependencies(['mime.charstream']) |
|
85 | + |
|
86 | + ->register('mime.charstream') |
|
87 | + ->asNewInstanceOf('Swift_CharacterStream_NgCharacterStream') |
|
88 | + ->withDependencies(['mime.characterreaderfactory', 'properties.charset']) |
|
89 | + |
|
90 | + ->register('mime.bytecanonicalizer') |
|
91 | + ->asSharedInstanceOf('Swift_StreamFilters_ByteArrayReplacementFilter') |
|
92 | + ->addConstructorValue([[0x0D, 0x0A], [0x0D], [0x0A]]) |
|
93 | + ->addConstructorValue([[0x0A], [0x0A], [0x0D, 0x0A]]) |
|
94 | + |
|
95 | + ->register('mime.characterreaderfactory') |
|
96 | + ->asSharedInstanceOf('Swift_CharacterReaderFactory_SimpleCharacterReaderFactory') |
|
97 | + |
|
98 | + ->register('mime.textcontentencoder') |
|
99 | + ->asAliasOf('mime.qpcontentencoder') |
|
100 | + |
|
101 | + ->register('mime.safeqpcontentencoder') |
|
102 | + ->asNewInstanceOf('Swift_Mime_ContentEncoder_QpContentEncoder') |
|
103 | + ->withDependencies(['mime.charstream', 'mime.bytecanonicalizer']) |
|
104 | + |
|
105 | + ->register('mime.rawcontentencoder') |
|
106 | + ->asNewInstanceOf('Swift_Mime_ContentEncoder_RawContentEncoder') |
|
107 | + |
|
108 | + ->register('mime.nativeqpcontentencoder') |
|
109 | + ->withDependencies(['properties.charset']) |
|
110 | + ->asNewInstanceOf('Swift_Mime_ContentEncoder_NativeQpContentEncoder') |
|
111 | + |
|
112 | + ->register('mime.qpcontentencoder') |
|
113 | + ->asNewInstanceOf('Swift_Mime_ContentEncoder_QpContentEncoderProxy') |
|
114 | + ->withDependencies(['mime.safeqpcontentencoder', 'mime.nativeqpcontentencoder', 'properties.charset']) |
|
115 | + |
|
116 | + ->register('mime.7bitcontentencoder') |
|
117 | + ->asNewInstanceOf('Swift_Mime_ContentEncoder_PlainContentEncoder') |
|
118 | + ->addConstructorValue('7bit') |
|
119 | + ->addConstructorValue(true) |
|
120 | + |
|
121 | + ->register('mime.8bitcontentencoder') |
|
122 | + ->asNewInstanceOf('Swift_Mime_ContentEncoder_PlainContentEncoder') |
|
123 | + ->addConstructorValue('8bit') |
|
124 | + ->addConstructorValue(true) |
|
125 | + |
|
126 | + ->register('mime.base64contentencoder') |
|
127 | + ->asSharedInstanceOf('Swift_Mime_ContentEncoder_Base64ContentEncoder') |
|
128 | + |
|
129 | + ->register('mime.rfc2231encoder') |
|
130 | + ->asNewInstanceOf('Swift_Encoder_Rfc2231Encoder') |
|
131 | + ->withDependencies(['mime.charstream']) |
|
132 | 132 | ; |
133 | 133 | |
134 | 134 | unset($swift_mime_types); |
@@ -1,9 +1,9 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | Swift_DependencyContainer::getInstance() |
4 | - ->register('message.message') |
|
5 | - ->asNewInstanceOf('Swift_Message') |
|
4 | + ->register('message.message') |
|
5 | + ->asNewInstanceOf('Swift_Message') |
|
6 | 6 | |
7 | - ->register('message.mimepart') |
|
8 | - ->asNewInstanceOf('Swift_MimePart') |
|
7 | + ->register('message.mimepart') |
|
8 | + ->asNewInstanceOf('Swift_MimePart') |
|
9 | 9 | ; |
@@ -1,97 +1,97 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | Swift_DependencyContainer::getInstance() |
4 | - ->register('transport.localdomain') |
|
5 | - // As SERVER_NAME can come from the user in certain configurations, check that |
|
6 | - // it does not contain forbidden characters (see RFC 952 and RFC 2181). Use |
|
7 | - // preg_replace() instead of preg_match() to prevent DoS attacks with long host names. |
|
8 | - ->asValue(!empty($_SERVER['SERVER_NAME']) && '' === preg_replace('/(?:^\[)?[a-zA-Z0-9-:\]_]+\.?/', '', $_SERVER['SERVER_NAME']) ? trim($_SERVER['SERVER_NAME'], '[]') : '127.0.0.1') |
|
9 | - |
|
10 | - ->register('transport.smtp') |
|
11 | - ->asNewInstanceOf('Swift_Transport_EsmtpTransport') |
|
12 | - ->withDependencies([ |
|
13 | - 'transport.buffer', |
|
14 | - 'transport.smtphandlers', |
|
15 | - 'transport.eventdispatcher', |
|
16 | - 'transport.localdomain', |
|
17 | - 'address.idnaddressencoder', |
|
18 | - ]) |
|
19 | - |
|
20 | - ->register('transport.sendmail') |
|
21 | - ->asNewInstanceOf('Swift_Transport_SendmailTransport') |
|
22 | - ->withDependencies([ |
|
23 | - 'transport.buffer', |
|
24 | - 'transport.eventdispatcher', |
|
25 | - 'transport.localdomain', |
|
26 | - ]) |
|
27 | - |
|
28 | - ->register('transport.loadbalanced') |
|
29 | - ->asNewInstanceOf('Swift_Transport_LoadBalancedTransport') |
|
30 | - |
|
31 | - ->register('transport.failover') |
|
32 | - ->asNewInstanceOf('Swift_Transport_FailoverTransport') |
|
33 | - |
|
34 | - ->register('transport.spool') |
|
35 | - ->asNewInstanceOf('Swift_Transport_SpoolTransport') |
|
36 | - ->withDependencies(['transport.eventdispatcher']) |
|
37 | - |
|
38 | - ->register('transport.null') |
|
39 | - ->asNewInstanceOf('Swift_Transport_NullTransport') |
|
40 | - ->withDependencies(['transport.eventdispatcher']) |
|
41 | - |
|
42 | - ->register('transport.buffer') |
|
43 | - ->asNewInstanceOf('Swift_Transport_StreamBuffer') |
|
44 | - ->withDependencies(['transport.replacementfactory']) |
|
45 | - |
|
46 | - ->register('transport.smtphandlers') |
|
47 | - ->asArray() |
|
48 | - ->withDependencies(['transport.authhandler']) |
|
49 | - |
|
50 | - ->register('transport.authhandler') |
|
51 | - ->asNewInstanceOf('Swift_Transport_Esmtp_AuthHandler') |
|
52 | - ->withDependencies(['transport.authhandlers']) |
|
53 | - |
|
54 | - ->register('transport.authhandlers') |
|
55 | - ->asArray() |
|
56 | - ->withDependencies([ |
|
57 | - 'transport.crammd5auth', |
|
58 | - 'transport.loginauth', |
|
59 | - 'transport.plainauth', |
|
60 | - 'transport.ntlmauth', |
|
61 | - 'transport.xoauth2auth', |
|
62 | - ]) |
|
63 | - |
|
64 | - ->register('transport.smtputf8handler') |
|
65 | - ->asNewInstanceOf('Swift_Transport_Esmtp_SmtpUtf8Handler') |
|
66 | - |
|
67 | - ->register('transport.8bitmimehandler') |
|
68 | - ->asNewInstanceOf('Swift_Transport_Esmtp_EightBitMimeHandler') |
|
69 | - ->addConstructorValue('8BITMIME') |
|
70 | - |
|
71 | - ->register('transport.crammd5auth') |
|
72 | - ->asNewInstanceOf('Swift_Transport_Esmtp_Auth_CramMd5Authenticator') |
|
73 | - |
|
74 | - ->register('transport.loginauth') |
|
75 | - ->asNewInstanceOf('Swift_Transport_Esmtp_Auth_LoginAuthenticator') |
|
76 | - |
|
77 | - ->register('transport.plainauth') |
|
78 | - ->asNewInstanceOf('Swift_Transport_Esmtp_Auth_PlainAuthenticator') |
|
79 | - |
|
80 | - ->register('transport.xoauth2auth') |
|
81 | - ->asNewInstanceOf('Swift_Transport_Esmtp_Auth_XOAuth2Authenticator') |
|
82 | - |
|
83 | - ->register('transport.ntlmauth') |
|
84 | - ->asNewInstanceOf('Swift_Transport_Esmtp_Auth_NTLMAuthenticator') |
|
85 | - |
|
86 | - ->register('transport.eventdispatcher') |
|
87 | - ->asNewInstanceOf('Swift_Events_SimpleEventDispatcher') |
|
88 | - |
|
89 | - ->register('transport.replacementfactory') |
|
90 | - ->asSharedInstanceOf('Swift_StreamFilters_StringReplacementFilterFactory') |
|
91 | - |
|
92 | - ->register('address.idnaddressencoder') |
|
93 | - ->asNewInstanceOf('Swift_AddressEncoder_IdnAddressEncoder') |
|
94 | - |
|
95 | - ->register('address.utf8addressencoder') |
|
96 | - ->asNewInstanceOf('Swift_AddressEncoder_Utf8AddressEncoder') |
|
4 | + ->register('transport.localdomain') |
|
5 | + // As SERVER_NAME can come from the user in certain configurations, check that |
|
6 | + // it does not contain forbidden characters (see RFC 952 and RFC 2181). Use |
|
7 | + // preg_replace() instead of preg_match() to prevent DoS attacks with long host names. |
|
8 | + ->asValue(!empty($_SERVER['SERVER_NAME']) && '' === preg_replace('/(?:^\[)?[a-zA-Z0-9-:\]_]+\.?/', '', $_SERVER['SERVER_NAME']) ? trim($_SERVER['SERVER_NAME'], '[]') : '127.0.0.1') |
|
9 | + |
|
10 | + ->register('transport.smtp') |
|
11 | + ->asNewInstanceOf('Swift_Transport_EsmtpTransport') |
|
12 | + ->withDependencies([ |
|
13 | + 'transport.buffer', |
|
14 | + 'transport.smtphandlers', |
|
15 | + 'transport.eventdispatcher', |
|
16 | + 'transport.localdomain', |
|
17 | + 'address.idnaddressencoder', |
|
18 | + ]) |
|
19 | + |
|
20 | + ->register('transport.sendmail') |
|
21 | + ->asNewInstanceOf('Swift_Transport_SendmailTransport') |
|
22 | + ->withDependencies([ |
|
23 | + 'transport.buffer', |
|
24 | + 'transport.eventdispatcher', |
|
25 | + 'transport.localdomain', |
|
26 | + ]) |
|
27 | + |
|
28 | + ->register('transport.loadbalanced') |
|
29 | + ->asNewInstanceOf('Swift_Transport_LoadBalancedTransport') |
|
30 | + |
|
31 | + ->register('transport.failover') |
|
32 | + ->asNewInstanceOf('Swift_Transport_FailoverTransport') |
|
33 | + |
|
34 | + ->register('transport.spool') |
|
35 | + ->asNewInstanceOf('Swift_Transport_SpoolTransport') |
|
36 | + ->withDependencies(['transport.eventdispatcher']) |
|
37 | + |
|
38 | + ->register('transport.null') |
|
39 | + ->asNewInstanceOf('Swift_Transport_NullTransport') |
|
40 | + ->withDependencies(['transport.eventdispatcher']) |
|
41 | + |
|
42 | + ->register('transport.buffer') |
|
43 | + ->asNewInstanceOf('Swift_Transport_StreamBuffer') |
|
44 | + ->withDependencies(['transport.replacementfactory']) |
|
45 | + |
|
46 | + ->register('transport.smtphandlers') |
|
47 | + ->asArray() |
|
48 | + ->withDependencies(['transport.authhandler']) |
|
49 | + |
|
50 | + ->register('transport.authhandler') |
|
51 | + ->asNewInstanceOf('Swift_Transport_Esmtp_AuthHandler') |
|
52 | + ->withDependencies(['transport.authhandlers']) |
|
53 | + |
|
54 | + ->register('transport.authhandlers') |
|
55 | + ->asArray() |
|
56 | + ->withDependencies([ |
|
57 | + 'transport.crammd5auth', |
|
58 | + 'transport.loginauth', |
|
59 | + 'transport.plainauth', |
|
60 | + 'transport.ntlmauth', |
|
61 | + 'transport.xoauth2auth', |
|
62 | + ]) |
|
63 | + |
|
64 | + ->register('transport.smtputf8handler') |
|
65 | + ->asNewInstanceOf('Swift_Transport_Esmtp_SmtpUtf8Handler') |
|
66 | + |
|
67 | + ->register('transport.8bitmimehandler') |
|
68 | + ->asNewInstanceOf('Swift_Transport_Esmtp_EightBitMimeHandler') |
|
69 | + ->addConstructorValue('8BITMIME') |
|
70 | + |
|
71 | + ->register('transport.crammd5auth') |
|
72 | + ->asNewInstanceOf('Swift_Transport_Esmtp_Auth_CramMd5Authenticator') |
|
73 | + |
|
74 | + ->register('transport.loginauth') |
|
75 | + ->asNewInstanceOf('Swift_Transport_Esmtp_Auth_LoginAuthenticator') |
|
76 | + |
|
77 | + ->register('transport.plainauth') |
|
78 | + ->asNewInstanceOf('Swift_Transport_Esmtp_Auth_PlainAuthenticator') |
|
79 | + |
|
80 | + ->register('transport.xoauth2auth') |
|
81 | + ->asNewInstanceOf('Swift_Transport_Esmtp_Auth_XOAuth2Authenticator') |
|
82 | + |
|
83 | + ->register('transport.ntlmauth') |
|
84 | + ->asNewInstanceOf('Swift_Transport_Esmtp_Auth_NTLMAuthenticator') |
|
85 | + |
|
86 | + ->register('transport.eventdispatcher') |
|
87 | + ->asNewInstanceOf('Swift_Events_SimpleEventDispatcher') |
|
88 | + |
|
89 | + ->register('transport.replacementfactory') |
|
90 | + ->asSharedInstanceOf('Swift_StreamFilters_StringReplacementFilterFactory') |
|
91 | + |
|
92 | + ->register('address.idnaddressencoder') |
|
93 | + ->asNewInstanceOf('Swift_AddressEncoder_IdnAddressEncoder') |
|
94 | + |
|
95 | + ->register('address.utf8addressencoder') |
|
96 | + ->asNewInstanceOf('Swift_AddressEncoder_Utf8AddressEncoder') |
|
97 | 97 | ; |