This commit is contained in:
Javier Garcia 2018-05-23 18:48:28 +02:00
parent d54cc6efee
commit a228811a61
2 changed files with 38 additions and 36 deletions

View File

@ -20,9 +20,9 @@ namespace PhpOffice\PhpWord\Shared;
use PhpOffice\PhpWord\Element\AbstractContainer; use PhpOffice\PhpWord\Element\AbstractContainer;
use PhpOffice\PhpWord\Element\Row; use PhpOffice\PhpWord\Element\Row;
use PhpOffice\PhpWord\Element\Table; use PhpOffice\PhpWord\Element\Table;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\SimpleType\Jc; use PhpOffice\PhpWord\SimpleType\Jc;
use PhpOffice\PhpWord\SimpleType\NumberFormat; use PhpOffice\PhpWord\SimpleType\NumberFormat;
use PhpOffice\PhpWord\Settings;
/** /**
* Common Html functions * Common Html functions
@ -305,7 +305,6 @@ class Html
*/ */
private static function parseTable($node, $element, &$styles) private static function parseTable($node, $element, &$styles)
{ {
$elementStyles = self::parseInlineStyle($node, $styles['table']); $elementStyles = self::parseInlineStyle($node, $styles['table']);
$newElement = $element->addTable($elementStyles); $newElement = $element->addTable($elementStyles);
@ -656,20 +655,20 @@ class Html
break; break;
} }
} }
if( strpos( $src, "data:image" ) !== false ){ if (strpos($src, 'data:image') !== false) {
if( ! is_dir( self::$imgdir ) ) if (!is_dir(self::$imgdir)) {
mkdir(self::$imgdir); mkdir(self::$imgdir);
}
$match = array(); $match = array();
preg_match('/data:image\/(\w+);base64,(.+)/', $src, $match); preg_match('/data:image\/(\w+);base64,(.+)/', $src, $match);
$src = $imgFile = self::$imgdir . uniqid() . "." . $match[1]; $src = $imgFile = self::$imgdir . uniqid() . '.' . $match[1];
$ifp = fopen( $imgFile, "wb"); $ifp = fopen($imgFile, 'wb');
fwrite($ifp, base64_decode($match[2])); fwrite($ifp, base64_decode($match[2]));
fclose($ifp); fclose($ifp);
} }
$src = urldecode($src); $src = urldecode($src);
@ -683,13 +682,14 @@ class Html
if (!is_file($src)) { if (!is_file($src)) {
if ($imgBlob = file_get_contents($src)) { if ($imgBlob = file_get_contents($src)) {
$tmpDir = Settings::getTempDir() . '/'; $tmpDir = Settings::getTempDir() . '/';
if( ! is_dir( $tmpDir ) ) if (!is_dir($tmpDir)) {
mkdir($tmpDir); mkdir($tmpDir);
}
$match = array(); $match = array();
preg_match('/.+\.(\w+)$/', $src, $match); preg_match('/.+\.(\w+)$/', $src, $match);
$src = $tmpDir . uniqid() . "." . $match[1]; $src = $tmpDir . uniqid() . '.' . $match[1];
$ifp = fopen( $src, "wb"); $ifp = fopen($src, 'wb');
fwrite($ifp, $imgBlob); fwrite($ifp, $imgBlob);
fclose($ifp); fclose($ifp);

View File

@ -115,6 +115,7 @@ class HtmlTest extends \PHPUnit\Framework\TestCase
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:rPr/w:u')); $this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:rPr/w:u'));
$this->assertEquals('single', $doc->getElementAttribute('/w:document/w:body/w:p/w:r/w:rPr/w:u', 'w:val')); $this->assertEquals('single', $doc->getElementAttribute('/w:document/w:body/w:p/w:r/w:rPr/w:u', 'w:val'));
} }
/** /**
* Test font * Test font
*/ */
@ -478,6 +479,7 @@ class HtmlTest extends \PHPUnit\Framework\TestCase
$baseXpath = '/w:document/w:body/w:p/w:r'; $baseXpath = '/w:document/w:body/w:p/w:r';
$this->assertTrue($doc->elementExists($baseXpath . '/w:pict/v:shape')); $this->assertTrue($doc->elementExists($baseXpath . '/w:pict/v:shape'));
} }
/** /**
* Test parsing of remote img that can be found locally * Test parsing of remote img that can be found locally
*/ */
@ -487,7 +489,7 @@ class HtmlTest extends \PHPUnit\Framework\TestCase
$localPath = __DIR__ . '/../_files/images/'; $localPath = __DIR__ . '/../_files/images/';
$options = array( $options = array(
'IMG_SRC_SEARCH' => 'https://fakedomain.io/images/', 'IMG_SRC_SEARCH' => 'https://fakedomain.io/images/',
'IMG_SRC_REPLACE'=> $localPath 'IMG_SRC_REPLACE' => $localPath,
); );
$phpWord = new \PhpOffice\PhpWord\PhpWord(); $phpWord = new \PhpOffice\PhpWord\PhpWord();