|
20 | 20 | use PhpOffice\PhpWord\Element\AbstractContainer;
|
21 | 21 | use PhpOffice\PhpWord\Element\Row;
|
22 | 22 | use PhpOffice\PhpWord\Element\Table;
|
| 23 | +use PhpOffice\PhpWord\Settings; |
23 | 24 | use PhpOffice\PhpWord\SimpleType\Jc;
|
24 | 25 | use PhpOffice\PhpWord\SimpleType\NumberFormat;
|
25 |
| -use PhpOffice\PhpWord\Settings; |
26 | 26 |
|
27 | 27 | /**
|
28 | 28 | * Common Html functions
|
@@ -50,7 +50,7 @@ class Html
|
50 | 50 | * + IMG_SRC_SEARCH: optional to speed up images loading from remote url when files can be found locally
|
51 | 51 | * + IMG_SRC_REPLACE: optional to speed up images loading from remote url when files can be found locally
|
52 | 52 | */
|
53 |
| - public static function addHtml($element, $html, $fullHTML = false, $preserveWhiteSpace = true, $options = null ) |
| 53 | + public static function addHtml($element, $html, $fullHTML = false, $preserveWhiteSpace = true, $options = null) |
54 | 54 | {
|
55 | 55 | /*
|
56 | 56 | * @todo parse $stylesheet for default styles. Should result in an array based on id, class and element,
|
@@ -303,9 +303,8 @@ private static function parseSpan($node, &$styles)
|
303 | 303 | *
|
304 | 304 | * @todo As soon as TableItem, RowItem and CellItem support relative width and height
|
305 | 305 | */
|
306 |
| - private static function parseTable($node, $element, &$styles ) |
| 306 | + private static function parseTable($node, $element, &$styles) |
307 | 307 | {
|
308 |
| - |
309 | 308 | $elementStyles = self::parseInlineStyle($node, $styles['table']);
|
310 | 309 |
|
311 | 310 | $newElement = $element->addTable($elementStyles);
|
@@ -656,45 +655,46 @@ private static function parseImage($node, $element)
|
656 | 655 | break;
|
657 | 656 | }
|
658 | 657 | }
|
659 |
| - if( strpos( $src, "data:image" ) !== false ){ |
660 |
| - if( ! is_dir( self::$imgdir ) ) |
661 |
| - mkdir( self::$imgdir ) ; |
662 |
| - |
663 |
| - $match = array(); |
664 |
| - preg_match( '/data:image\/(\w+);base64,(.+)/', $src, $match ); |
| 658 | + if (strpos($src, 'data:image') !== false) { |
| 659 | + if (!is_dir(self::$imgdir)) { |
| 660 | + mkdir(self::$imgdir); |
| 661 | + } |
665 | 662 |
|
666 |
| - $src = $imgFile = self::$imgdir . uniqid() . "." . $match[1]; |
| 663 | + $match = array(); |
| 664 | + preg_match('/data:image\/(\w+);base64,(.+)/', $src, $match); |
667 | 665 |
|
668 |
| - $ifp = fopen( $imgFile, "wb"); |
| 666 | + $src = $imgFile = self::$imgdir . uniqid() . '.' . $match[1]; |
669 | 667 |
|
670 |
| - fwrite($ifp, base64_decode( $match[2] ) ); |
671 |
| - fclose($ifp); |
| 668 | + $ifp = fopen($imgFile, 'wb'); |
672 | 669 |
|
673 |
| - } |
674 |
| - $src= urldecode($src); |
| 670 | + fwrite($ifp, base64_decode($match[2])); |
| 671 | + fclose($ifp); |
| 672 | + } |
| 673 | + $src = urldecode($src); |
675 | 674 |
|
676 |
| - if( ! is_file( $src ) |
| 675 | + if (!is_file($src) |
677 | 676 | && !is_null(self::$options)
|
678 | 677 | && isset(self::$options['IMG_SRC_SEARCH'])
|
679 |
| - && isset(self::$options['IMG_SRC_REPLACE'])){ |
680 |
| - $src = str_replace( self::$options['IMG_SRC_SEARCH'], self::$options['IMG_SRC_REPLACE'], $src ); |
681 |
| - } |
682 |
| - |
683 |
| - if(! is_file($src)){ |
684 |
| - if($imgBlob=file_get_contents($src)){ |
685 |
| - $tmpDir= Settings::getTempDir().'/'; |
686 |
| - if( ! is_dir( $tmpDir ) ) |
687 |
| - mkdir( $tmpDir ) ; |
688 |
| - $match = array(); |
689 |
| - preg_match( '/.+\.(\w+)$/', $src, $match ); |
690 |
| - $src = $tmpDir . uniqid() . "." . $match[1]; |
691 |
| - |
692 |
| - $ifp = fopen( $src, "wb"); |
693 |
| - |
694 |
| - fwrite($ifp, $imgBlob ); |
695 |
| - fclose($ifp); |
696 |
| - } |
697 |
| - } |
| 678 | + && isset(self::$options['IMG_SRC_REPLACE'])) { |
| 679 | + $src = str_replace(self::$options['IMG_SRC_SEARCH'], self::$options['IMG_SRC_REPLACE'], $src); |
| 680 | + } |
| 681 | + |
| 682 | + if (!is_file($src)) { |
| 683 | + if ($imgBlob = file_get_contents($src)) { |
| 684 | + $tmpDir = Settings::getTempDir() . '/'; |
| 685 | + if (!is_dir($tmpDir)) { |
| 686 | + mkdir($tmpDir); |
| 687 | + } |
| 688 | + $match = array(); |
| 689 | + preg_match('/.+\.(\w+)$/', $src, $match); |
| 690 | + $src = $tmpDir . uniqid() . '.' . $match[1]; |
| 691 | + |
| 692 | + $ifp = fopen($src, 'wb'); |
| 693 | + |
| 694 | + fwrite($ifp, $imgBlob); |
| 695 | + fclose($ifp); |
| 696 | + } |
| 697 | + } |
698 | 698 | $newElement = $element->addImage($src, $style);
|
699 | 699 |
|
700 | 700 | return $newElement;
|
|
0 commit comments