Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/PhpWord/Reader/Word2007.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,20 @@ 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);
$type = str_replace($officePrefix, '', $type);
$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);

Expand Down
18 changes: 12 additions & 6 deletions src/PhpWord/Reader/Word2007/AbstractPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -216,17 +216,21 @@ 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);
}

// Object
} 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 = "<Object: {$target}>";
$parent->addText($textContent, $fontStyle, $paragraphStyle);
Expand Down Expand Up @@ -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);
}
}
6 changes: 3 additions & 3 deletions src/PhpWord/Shared/PCLZip/pclzip.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -226,7 +226,7 @@ function PclZip($p_zipname)
$this->zip_fd = 0;
$this->magic_quotes_status = -1;

// ----- Return
// ----- Constructors should not Return anything
return;
}
// --------------------------------------------------------------------------------
Expand Down