updates from Dan

This commit is contained in:
Dave Umrysh 2023-12-13 14:50:03 -07:00
parent 4d2d12e67b
commit 754b5a33d5
1 changed files with 27 additions and 5 deletions

View File

@ -29,6 +29,9 @@ use PhpOffice\PhpWord\Shared\ZipArchive;
class TemplateProcessor
{
const MAXIMUM_REPLACEMENTS_DEFAULT = -1;
private int $countRels = 100; //start id for relationship between image and document.xml
private $rels;
private $types;
/**
* ZipArchive object.
@ -130,7 +133,8 @@ class TemplateProcessor
$this->tempDocumentSettingsPart = $this->readPartWithRels($this->getSettingsPartName());
$this->tempDocumentContentTypes = $this->zipClass->getFromName($this->getDocumentContentTypesName());
$this->_countRels=100; //start id for relationship between image and document.xml
// DEPRECATED
//$this->_countRels=100; //start id for relationship between image and document.xml
}
/**
@ -841,13 +845,22 @@ class TemplateProcessor
$this->zipClass->addFromString($this->getDocumentContentTypesName(), $this->tempDocumentContentTypes);
if(isset($this->_rels) && $this->_rels!="")
/*if(isset($this->_rels) && $this->_rels!="")
{
$this->zipClass->addFromString('word/_rels/document.xml.rels', $this->_rels);
}
if(isset($this->_types) && $this->_types!="")
{
$this->zipClass->addFromString('[Content_Types].xml', $this->_types);
}*/
if(isset($this->rels) && $this->rels!="")
{
$this->zipClass->addFromString('word/_rels/document.xml.rels', $this->rels);
}
if(isset($this->types) && $this->types!="")
{
$this->zipClass->addFromString('[Content_Types].xml', $this->types);
}
// Close zip file
@ -1270,7 +1283,7 @@ class TemplateProcessor
$toAdd = $toAddImg = $toAddType = '';
$aSearch = array('RID', 'IMG');
$aSearchType = array('IMG', 'EXT');
$countrels=$this->_countRels++;
$countrels=$this->countRels++;
//I'm work for jpg files, if you are working with other images types -> Write conditions here
$imgExt = 'jpg';
$imgName = 'img' . $countrels . '.' . $imgExt;
@ -1330,14 +1343,23 @@ class TemplateProcessor
if(!isset($this->_rels) || (isset($this->_rels) && $this->_rels==""))
/*if(!isset($this->_rels) || (isset($this->_rels) && $this->_rels==""))
{
$this->_rels=$this->zipClass->getFromName('word/_rels/document.xml.rels');
$this->_types=$this->zipClass->getFromName('[Content_Types].xml');
}
$this->_types = str_replace('</Types>', $toAddType, $this->_types) . '</Types>';
$this->_rels = str_replace('</Relationships>', $toAdd, $this->_rels) . '</Relationships>';
$this->_rels = str_replace('</Relationships>', $toAdd, $this->_rels) . '</Relationships>';*/
if(!isset($this->rels) || (isset($this->rels) && $this->rels==""))
{
$this->rels=$this->zipClass->getFromName('word/_rels/document.xml.rels');
$this->types=$this->zipClass->getFromName('[Content_Types].xml');
}
$this->types = str_replace('</Types>', $toAddType, $this->types) . '</Types>';
$this->rels = str_replace('</Relationships>', $toAdd, $this->rels) . '</Relationships>';
}
function limpiarString($str) {