Skip to content

Commit d905e76

Browse files
authored
Merge pull request #2063 from tpv-ebben/develop
when adding image to relationship first check that the generated RID is actually unique
2 parents d6e0a3e + 7fd0489 commit d905e76

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/PhpWord/TemplateProcessor.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* This file is part of PHPWord - A pure PHP library for reading and writing
45
* word processing documents.
@@ -620,8 +621,8 @@ public function setImageValue($search, $replace, $limit = self::MAXIMUM_REPLACEM
620621

621622
// collect document parts
622623
$searchParts = array(
623-
$this->getMainPartName() => &$this->tempDocumentMainPart,
624-
);
624+
$this->getMainPartName() => &$this->tempDocumentMainPart,
625+
);
625626
foreach (array_keys($this->tempDocumentHeaders) as $headerIndex) {
626627
$searchParts[$this->getHeaderName($headerIndex)] = &$this->tempDocumentHeaders[$headerIndex];
627628
}
@@ -748,7 +749,8 @@ public function cloneRow($search, $numberOfClones)
748749
// If tmpXmlRow doesn't contain continue, this row is no longer part of the spanned row.
749750
$tmpXmlRow = $this->getSlice($extraRowStart, $extraRowEnd);
750751
if (!preg_match('#<w:vMerge/>#', $tmpXmlRow) &&
751-
!preg_match('#<w:vMerge w:val="continue"\s*/>#', $tmpXmlRow)) {
752+
!preg_match('#<w:vMerge w:val="continue"\s*/>#', $tmpXmlRow)
753+
) {
752754
break;
753755
}
754756
// This row was a spanned row, update $rowEnd and search for the next row.
@@ -1067,7 +1069,12 @@ protected function getRelationsName($documentPartName)
10671069
protected function getNextRelationsIndex($documentPartName)
10681070
{
10691071
if (isset($this->tempDocumentRelations[$documentPartName])) {
1070-
return substr_count($this->tempDocumentRelations[$documentPartName], '<Relationship');
1072+
$candidate = substr_count($this->tempDocumentRelations[$documentPartName], '<Relationship');
1073+
while (strpos($this->tempDocumentRelations[$documentPartName], 'Id="rId' . $candidate . '"') !== false) {
1074+
$candidate++;
1075+
}
1076+
1077+
return $candidate;
10711078
}
10721079

10731080
return 1;

0 commit comments

Comments
 (0)