2012-05-06 18:25:40 +02:00
|
|
|
<?php
|
|
|
|
|
/**
|
2014-03-26 16:33:20 +07:00
|
|
|
* PHPWord
|
2012-05-06 18:25:40 +02:00
|
|
|
*
|
2014-03-27 23:55:06 +07:00
|
|
|
* @link https://github.com/PHPOffice/PHPWord
|
|
|
|
|
* @copyright 2014 PHPWord
|
|
|
|
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
2012-05-06 18:25:40 +02:00
|
|
|
*/
|
|
|
|
|
|
2014-03-22 10:06:08 +04:00
|
|
|
namespace PhpOffice\PhpWord\Writer\Word2007;
|
|
|
|
|
|
2014-03-23 10:32:08 +04:00
|
|
|
use PhpOffice\PhpWord\Exceptions\Exception;
|
2014-03-22 10:06:08 +04:00
|
|
|
use PhpOffice\PhpWord\PhpWord;
|
|
|
|
|
use PhpOffice\PhpWord\Shared\XMLWriter;
|
|
|
|
|
|
2014-03-24 00:26:10 +07:00
|
|
|
/**
|
|
|
|
|
* Word2007 rels part writer
|
|
|
|
|
*/
|
2014-03-22 10:06:08 +04:00
|
|
|
class Rels extends WriterPart
|
2013-12-11 14:45:44 -05:00
|
|
|
{
|
2014-03-24 00:26:10 +07:00
|
|
|
/**
|
|
|
|
|
* Write _rels/.rels
|
|
|
|
|
*
|
|
|
|
|
* @param PhpOffice\PhpWord\PhpWord $phpWord
|
|
|
|
|
*/
|
2014-03-22 10:06:08 +04:00
|
|
|
public function writeRelationships(PhpWord $phpWord = null)
|
2013-12-11 14:45:44 -05:00
|
|
|
{
|
|
|
|
|
// Create XML writer
|
2014-03-22 10:06:08 +04:00
|
|
|
$xmlWriter = null;
|
2013-12-11 14:45:44 -05:00
|
|
|
if ($this->getParentWriter()->getUseDiskCaching()) {
|
2014-03-22 10:06:08 +04:00
|
|
|
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
|
2013-12-11 14:45:44 -05:00
|
|
|
} else {
|
2014-03-22 10:06:08 +04:00
|
|
|
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
|
2013-12-11 14:45:44 -05:00
|
|
|
}
|
2012-05-06 18:25:40 +02:00
|
|
|
|
2013-12-11 14:45:44 -05:00
|
|
|
// XML header
|
2014-03-22 10:06:08 +04:00
|
|
|
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
|
2012-05-06 18:25:40 +02:00
|
|
|
|
2013-12-11 14:45:44 -05:00
|
|
|
// Relationships
|
2014-03-22 10:06:08 +04:00
|
|
|
$xmlWriter->startElement('Relationships');
|
|
|
|
|
$xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
|
2012-05-06 18:25:40 +02:00
|
|
|
|
2013-12-11 14:45:44 -05:00
|
|
|
$relationId = 1;
|
2012-05-06 18:25:40 +02:00
|
|
|
|
2013-12-11 14:45:44 -05:00
|
|
|
// Relationship word/document.xml
|
|
|
|
|
$this->_writeRelationship(
|
2014-03-22 10:06:08 +04:00
|
|
|
$xmlWriter,
|
2013-12-11 14:45:44 -05:00
|
|
|
$relationId,
|
|
|
|
|
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument',
|
|
|
|
|
'word/document.xml'
|
|
|
|
|
);
|
2012-05-06 18:25:40 +02:00
|
|
|
|
2013-12-11 14:45:44 -05:00
|
|
|
// Relationship docProps/core.xml
|
|
|
|
|
$this->_writeRelationship(
|
2014-03-22 10:06:08 +04:00
|
|
|
$xmlWriter,
|
2013-12-11 14:45:44 -05:00
|
|
|
++$relationId,
|
|
|
|
|
'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties',
|
|
|
|
|
'docProps/core.xml'
|
|
|
|
|
);
|
2012-05-06 18:25:40 +02:00
|
|
|
|
2013-12-11 14:45:44 -05:00
|
|
|
// Relationship docProps/app.xml
|
|
|
|
|
$this->_writeRelationship(
|
2014-03-22 10:06:08 +04:00
|
|
|
$xmlWriter,
|
2013-12-11 14:45:44 -05:00
|
|
|
++$relationId,
|
|
|
|
|
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties',
|
|
|
|
|
'docProps/app.xml'
|
|
|
|
|
);
|
|
|
|
|
|
2014-03-22 10:06:08 +04:00
|
|
|
$xmlWriter->endElement();
|
2013-12-11 14:45:44 -05:00
|
|
|
|
2014-03-22 10:06:08 +04:00
|
|
|
return $xmlWriter->getData();
|
2013-12-11 14:45:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Write Override content type
|
|
|
|
|
*
|
2014-03-23 10:32:08 +04:00
|
|
|
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
|
|
|
|
* @param int $pId Relationship ID. rId will be prepended!
|
|
|
|
|
* @param string $pType Relationship type
|
|
|
|
|
* @param string $pTarget Relationship target
|
|
|
|
|
* @param string $pTargetMode Relationship target mode
|
|
|
|
|
* @throws \PhpOffice\PhpWord\Exceptions\Exception
|
2013-12-11 14:45:44 -05:00
|
|
|
*/
|
2014-03-22 10:06:08 +04:00
|
|
|
private function _writeRelationship(XMLWriter $xmlWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '')
|
2013-12-11 14:45:44 -05:00
|
|
|
{
|
|
|
|
|
if ($pType != '' && $pTarget != '') {
|
|
|
|
|
if (strpos($pId, 'rId') === false) {
|
|
|
|
|
$pId = 'rId' . $pId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Write relationship
|
2014-03-22 10:06:08 +04:00
|
|
|
$xmlWriter->startElement('Relationship');
|
|
|
|
|
$xmlWriter->writeAttribute('Id', $pId);
|
|
|
|
|
$xmlWriter->writeAttribute('Type', $pType);
|
|
|
|
|
$xmlWriter->writeAttribute('Target', $pTarget);
|
2013-12-11 14:45:44 -05:00
|
|
|
|
|
|
|
|
if ($pTargetMode != '') {
|
2014-03-22 10:06:08 +04:00
|
|
|
$xmlWriter->writeAttribute('TargetMode', $pTargetMode);
|
2013-12-11 14:45:44 -05:00
|
|
|
}
|
|
|
|
|
|
2014-03-22 10:06:08 +04:00
|
|
|
$xmlWriter->endElement();
|
2013-12-11 14:45:44 -05:00
|
|
|
} else {
|
|
|
|
|
throw new Exception("Invalid parameters passed.");
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-05-06 18:25:40 +02:00
|
|
|
}
|