From 97ceaba9e3617e53b01515b24e48560157e667a0 Mon Sep 17 00:00:00 2001 From: Nilton Date: Fri, 27 Oct 2017 05:26:30 +0200 Subject: [PATCH 1/2] Allow reading of TargetMode for external images --- src/PhpWord/Reader/Word2007.php | 5 +++-- src/PhpWord/Reader/Word2007/AbstractPart.php | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/PhpWord/Reader/Word2007.php b/src/PhpWord/Reader/Word2007.php index d203dd29ea..3e09b81b77 100644 --- a/src/PhpWord/Reader/Word2007.php +++ b/src/PhpWord/Reader/Word2007.php @@ -148,6 +148,7 @@ private function getRels($docFile, $xmlFile, $targetPrefix = '') $rId = $xmlReader->getAttribute('Id', $node); $type = $xmlReader->getAttribute('Type', $node); $target = $xmlReader->getAttribute('Target', $node); + $mode = $xmlReader->getAttribute('TargetMode', $node); // Remove URL prefixes from $type to make it easier to read $type = str_replace($metaPrefix, '', $type); @@ -155,12 +156,12 @@ private function getRels($docFile, $xmlFile, $targetPrefix = '') $docPart = str_replace('.xml', '', $target); // Do not add prefix to link source - if (!in_array($type, array('hyperlink'))) { + if ($type != 'hyperlink' && $mode != 'External') { $target = $targetPrefix . $target; } // Push to return array - $rels[$rId] = array('type' => $type, 'target' => $target, 'docPart' => $docPart); + $rels[$rId] = array('type' => $type, 'target' => $target, 'docPart' => $docPart, 'targetMode' => $mode); } ksort($rels); diff --git a/src/PhpWord/Reader/Word2007/AbstractPart.php b/src/PhpWord/Reader/Word2007/AbstractPart.php index c94a3546a8..5fd068468f 100644 --- a/src/PhpWord/Reader/Word2007/AbstractPart.php +++ b/src/PhpWord/Reader/Word2007/AbstractPart.php @@ -200,7 +200,7 @@ protected function readRun(XMLReader $xmlReader, \DOMElement $domNode, $parent, if ('w:hyperlink' == $domNode->nodeName) { $rId = $xmlReader->getAttribute('r:id', $domNode); $textContent = $xmlReader->getValue('w:r/w:t', $domNode); - $target = $this->getMediaTarget($docPart, $rId); + $target = $this->getMediaTarget($docPart, $rId)[0]; if (!is_null($target)) { $parent->addLink($target, $textContent, $fontStyle, $paragraphStyle); } @@ -216,9 +216,13 @@ protected function readRun(XMLReader $xmlReader, \DOMElement $domNode, $parent, // Image } elseif ($xmlReader->elementExists('w:pict', $domNode)) { $rId = $xmlReader->getAttribute('r:id', $domNode, 'w:pict/v:shape/v:imagedata'); - $target = $this->getMediaTarget($docPart, $rId); + list($target, $mode) = $this->getMediaTarget($docPart, $rId); if (!is_null($target)) { - $imageSource = "zip://{$this->docFile}#{$target}"; + if ($mode == 'External') { + $imageSource = $target; + } else { + $imageSource = "zip://{$this->docFile}#{$target}"; + } $parent->addImage($imageSource); } @@ -226,7 +230,7 @@ protected function readRun(XMLReader $xmlReader, \DOMElement $domNode, $parent, } elseif ($xmlReader->elementExists('w:object', $domNode)) { $rId = $xmlReader->getAttribute('r:id', $domNode, 'w:object/o:OLEObject'); // $rIdIcon = $xmlReader->getAttribute('r:id', $domNode, 'w:object/v:shape/v:imagedata'); - $target = $this->getMediaTarget($docPart, $rId); + $target = $this->getMediaTarget($docPart, $rId)[0]; if (!is_null($target)) { $textContent = ""; $parent->addText($textContent, $fontStyle, $paragraphStyle); @@ -499,16 +503,18 @@ private function readStyleDef($method, $attributeValue, $expected) * * @param string $docPart * @param string $rId - * @return string|null + * @return array */ private function getMediaTarget($docPart, $rId) { $target = null; + $targetMode = null; if (isset($this->rels[$docPart]) && isset($this->rels[$docPart][$rId])) { $target = $this->rels[$docPart][$rId]['target']; + $targetMode = $this->rels[$docPart][$rId]['targetMode']; } - return $target; + return array($target, $targetMode); } } From 9bcb65ac5e547fb9edbf1631cfff9b947df220bc Mon Sep 17 00:00:00 2001 From: Nilton Date: Fri, 27 Oct 2017 06:15:15 +0200 Subject: [PATCH 2/2] Make Travis happy with constructors written like php7 --- src/PhpWord/Shared/PCLZip/pclzip.lib.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PhpWord/Shared/PCLZip/pclzip.lib.php b/src/PhpWord/Shared/PCLZip/pclzip.lib.php index 4e2a496f20..c154062653 100644 --- a/src/PhpWord/Shared/PCLZip/pclzip.lib.php +++ b/src/PhpWord/Shared/PCLZip/pclzip.lib.php @@ -205,14 +205,14 @@ class PclZip var $magic_quotes_status; // -------------------------------------------------------------------------------- - // Function : PclZip() + // Function : __construct() // Description : // Creates a PclZip object and set the name of the associated Zip archive // filename. // Note that no real action is taken, if the archive does not exist it is not // created. Use create() for that. // -------------------------------------------------------------------------------- - function PclZip($p_zipname) + function __construct($p_zipname) { // ----- Tests the zlib @@ -226,7 +226,7 @@ function PclZip($p_zipname) $this->zip_fd = 0; $this->magic_quotes_status = -1; - // ----- Return + // ----- Constructors should not Return anything return; } // --------------------------------------------------------------------------------