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\Shared\XMLWriter;
|
|
|
|
|
|
2014-03-24 00:26:10 +07:00
|
|
|
/**
|
|
|
|
|
* Word2007 document rels part writer
|
|
|
|
|
*/
|
2014-03-30 18:51:25 +07:00
|
|
|
class DocumentRels extends Base
|
2013-12-11 14:45:44 -05:00
|
|
|
{
|
2014-03-24 00:26:10 +07:00
|
|
|
/**
|
|
|
|
|
* Write word/_rels/document.xml.rels
|
|
|
|
|
*
|
|
|
|
|
* @param array $_relsCollection
|
|
|
|
|
*/
|
2013-12-11 14:45:44 -05:00
|
|
|
public function writeDocumentRels($_relsCollection)
|
|
|
|
|
{
|
|
|
|
|
// Create XML writer
|
2014-03-30 16:31:01 +07:00
|
|
|
$xmlWriter = $this->getXmlWriter();
|
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');
|
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');
|
2013-12-11 14:45:44 -05:00
|
|
|
|
|
|
|
|
// Relationship word/document.xml
|
2014-03-30 18:51:25 +07:00
|
|
|
$this->writeRelationship(
|
2014-03-22 10:06:08 +04:00
|
|
|
$xmlWriter,
|
2013-12-11 14:45:44 -05:00
|
|
|
1,
|
|
|
|
|
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles',
|
|
|
|
|
'styles.xml'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Relationship word/numbering.xml
|
2014-03-30 18:51:25 +07:00
|
|
|
$this->writeRelationship(
|
2014-03-22 10:06:08 +04:00
|
|
|
$xmlWriter,
|
2013-12-11 14:45:44 -05:00
|
|
|
2,
|
|
|
|
|
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering',
|
|
|
|
|
'numbering.xml'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Relationship word/settings.xml
|
2014-03-30 18:51:25 +07:00
|
|
|
$this->writeRelationship(
|
2014-03-22 10:06:08 +04:00
|
|
|
$xmlWriter,
|
2013-12-11 14:45:44 -05:00
|
|
|
3,
|
|
|
|
|
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings',
|
|
|
|
|
'settings.xml'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Relationship word/settings.xml
|
2014-03-30 18:51:25 +07:00
|
|
|
$this->writeRelationship(
|
2014-03-22 10:06:08 +04:00
|
|
|
$xmlWriter,
|
2013-12-11 14:45:44 -05:00
|
|
|
4,
|
|
|
|
|
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme',
|
|
|
|
|
'theme/theme1.xml'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Relationship word/settings.xml
|
2014-03-30 18:51:25 +07:00
|
|
|
$this->writeRelationship(
|
2014-03-22 10:06:08 +04:00
|
|
|
$xmlWriter,
|
2013-12-11 14:45:44 -05:00
|
|
|
5,
|
|
|
|
|
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings',
|
|
|
|
|
'webSettings.xml'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Relationship word/settings.xml
|
2014-03-30 18:51:25 +07:00
|
|
|
$this->writeRelationship(
|
2014-03-22 10:06:08 +04:00
|
|
|
$xmlWriter,
|
2013-12-11 14:45:44 -05:00
|
|
|
6,
|
|
|
|
|
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable',
|
|
|
|
|
'fontTable.xml'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Relationships to Images / Embeddings / Headers / Footers
|
|
|
|
|
foreach ($_relsCollection as $relation) {
|
|
|
|
|
$relationType = $relation['type'];
|
|
|
|
|
$relationName = $relation['target'];
|
|
|
|
|
$relationId = $relation['rID'];
|
|
|
|
|
$targetMode = ($relationType == 'hyperlink') ? 'External' : '';
|
|
|
|
|
|
2014-03-30 18:51:25 +07:00
|
|
|
$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/' . $relationType,
|
|
|
|
|
$relationName,
|
|
|
|
|
$targetMode
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-03-22 10:06:08 +04:00
|
|
|
$xmlWriter->endElement();
|
2013-12-11 14:45:44 -05:00
|
|
|
|
|
|
|
|
// Return
|
2014-03-22 10:06:08 +04:00
|
|
|
return $xmlWriter->getData();
|
2013-12-11 14:45:44 -05:00
|
|
|
}
|
|
|
|
|
|
2014-03-24 00:26:10 +07:00
|
|
|
/**
|
|
|
|
|
* Write header footer rels
|
|
|
|
|
*
|
|
|
|
|
* @param array $_relsCollection
|
|
|
|
|
*/
|
2013-12-11 14:45:44 -05:00
|
|
|
public function writeHeaderFooterRels($_relsCollection)
|
|
|
|
|
{
|
|
|
|
|
// Create XML writer
|
2014-03-30 16:31:01 +07:00
|
|
|
$xmlWriter = $this->getXmlWriter();
|
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');
|
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');
|
2013-12-11 14:45:44 -05:00
|
|
|
|
|
|
|
|
// Relationships to Images / Embeddings / Headers / Footers
|
|
|
|
|
foreach ($_relsCollection as $relation) {
|
|
|
|
|
$relationType = $relation['type'];
|
|
|
|
|
$relationName = $relation['target'];
|
|
|
|
|
$relationId = $relation['rID'];
|
|
|
|
|
|
2014-03-30 18:51:25 +07:00
|
|
|
$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/' . $relationType,
|
|
|
|
|
$relationName
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-22 10:06:08 +04:00
|
|
|
|
|
|
|
|
$xmlWriter->endElement();
|
2013-12-11 14:45:44 -05:00
|
|
|
|
|
|
|
|
// Return
|
2014-03-22 10:06:08 +04:00
|
|
|
return $xmlWriter->getData();
|
2013-12-11 14:45:44 -05:00
|
|
|
}
|
2012-05-06 18:25:40 +02:00
|
|
|
}
|