Gabriel Bull 39e4dd2259 Merge branch 'master' of https://github.com/PHPOffice/PHPWord
Conflicts:
	.gitignore
	Classes/PHPWord.php
	Classes/PHPWord/Section.php
	Classes/PHPWord/Section/Footer.php
	Classes/PHPWord/Section/Header.php
	Classes/PHPWord/Section/Table/Cell.php
	Classes/PHPWord/Section/TextRun.php
	Classes/PHPWord/Shared/String.php
	Classes/PHPWord/Style/Cell.php
	Classes/PHPWord/Style/Paragraph.php
	Classes/PHPWord/Template.php
	Classes/PHPWord/Writer/Word2007.php
	Classes/PHPWord/Writer/Word2007/Base.php
	Classes/PHPWord/Writer/Word2007/Document.php
	Examples/AdvancedTable.php
	Examples/BasicTable.php
	Examples/HeaderFooter.php
	Examples/Link.php
	Examples/ListItem.php
	Examples/Object.php
	Examples/Section.php
	Examples/Template.php
	Examples/Textrun.php
	Examples/TitleTOC.php
	Examples/Watermark.php
	Examples/_earth.JPG
	Examples/_mars.jpg
	Examples/_sheet.xls
	changelog.txt
	samples/old/AdvancedTable.php
	samples/old/BasicTable.php
	samples/old/Image.php
	samples/old/Link.php
	samples/old/ListItem.php
	samples/old/Object.php
	samples/old/Section.php
	samples/old/Template.php
	samples/old/Textrun.php
	samples/old/TitleTOC.php
	samples/old/Watermark.php
	samples/old/_earth.jpg
	samples/old/_mars.jpg
	samples/old/_sheet.xls
	src/Examples/AdvancedTable.php
	src/Examples/BasicTable.php
	src/Examples/Link.php
	src/Examples/ListItem.php
	src/Examples/Object.php
	src/Examples/Section.php
	src/Examples/Template.php
	src/Examples/Textrun.php
	src/Examples/TitleTOC.php
	src/Examples/Watermark.php
	src/Examples/_earth.JPG
	src/Examples/_mars.jpg
	src/Examples/_sheet.xls
2013-12-15 14:15:28 -05:00

183 lines
6.1 KiB
PHP

<?php
/**
* PHPWord
*
* Copyright (c) 2013 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2013 PHPWord (http://www.codeplex.com/PHPWord)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.7.0
*/
/**
* Class PHPWord_Writer_Word2007_DocumentRels
*/
class PHPWord_Writer_Word2007_DocumentRels extends PHPWord_Writer_Word2007_WriterPart
{
public function writeDocumentRels($_relsCollection)
{
// Create XML writer
$objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
}
// XML header
$objWriter->startDocument('1.0', 'UTF-8', 'yes');
// Relationships
$objWriter->startElement('Relationships');
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
// Relationship word/document.xml
$this->_writeRelationship(
$objWriter,
1,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles',
'styles.xml'
);
// Relationship word/numbering.xml
$this->_writeRelationship(
$objWriter,
2,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering',
'numbering.xml'
);
// Relationship word/settings.xml
$this->_writeRelationship(
$objWriter,
3,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings',
'settings.xml'
);
// Relationship word/settings.xml
$this->_writeRelationship(
$objWriter,
4,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme',
'theme/theme1.xml'
);
// Relationship word/settings.xml
$this->_writeRelationship(
$objWriter,
5,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings',
'webSettings.xml'
);
// Relationship word/settings.xml
$this->_writeRelationship(
$objWriter,
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' : '';
$this->_writeRelationship(
$objWriter,
$relationId,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType,
$relationName,
$targetMode
);
}
$objWriter->endElement();
// Return
return $objWriter->getData();
}
public function writeHeaderFooterRels($_relsCollection)
{
// Create XML writer
$objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
}
// XML header
$objWriter->startDocument('1.0', 'UTF-8', 'yes');
// Relationships
$objWriter->startElement('Relationships');
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
// Relationships to Images / Embeddings / Headers / Footers
foreach ($_relsCollection as $relation) {
$relationType = $relation['type'];
$relationName = $relation['target'];
$relationId = $relation['rID'];
$this->_writeRelationship(
$objWriter,
$relationId,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType,
$relationName
);
}
$objWriter->endElement();
// Return
return $objWriter->getData();
}
private function _writeRelationship(PHPWord_Shared_XMLWriter $objWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '')
{
if ($pType != '' && $pTarget != '') {
if (strpos($pId, 'rId') === false) {
$pId = 'rId' . $pId;
}
// Write relationship
$objWriter->startElement('Relationship');
$objWriter->writeAttribute('Id', $pId);
$objWriter->writeAttribute('Type', $pType);
$objWriter->writeAttribute('Target', $pTarget);
if ($pTargetMode != '') {
$objWriter->writeAttribute('TargetMode', $pTargetMode);
}
$objWriter->endElement();
} else {
throw new Exception("Invalid parameters passed.");
}
}
}