2014-03-22 10:06:08 +04:00
|
|
|
<?php
|
|
|
|
|
/**
|
2014-03-26 16:33:20 +07:00
|
|
|
* PHPWord
|
2014-03-22 10:06:08 +04: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
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
|
|
|
|
|
2014-04-30 08:54:38 +07:00
|
|
|
namespace PhpOffice\PhpWord\Writer\Word2007\Part;
|
2014-03-22 10:06:08 +04:00
|
|
|
|
2014-03-31 01:13:02 +07:00
|
|
|
use PhpOffice\PhpWord\Element\Footnote;
|
2014-03-22 10:06:08 +04:00
|
|
|
use PhpOffice\PhpWord\Shared\XMLWriter;
|
2014-04-26 11:14:27 +07:00
|
|
|
use PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph as ParagraphStyleWriter;
|
2014-03-22 10:06:08 +04:00
|
|
|
|
2014-03-24 00:26:10 +07:00
|
|
|
/**
|
|
|
|
|
* Word2007 footnotes part writer
|
|
|
|
|
*/
|
2014-04-30 08:54:38 +07:00
|
|
|
class Footnotes extends AbstractPart
|
2014-03-22 10:06:08 +04:00
|
|
|
{
|
2014-04-30 08:54:38 +07:00
|
|
|
/**
|
|
|
|
|
* Name of XML root element
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $rootNode = 'w:footnotes';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Name of XML node element
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $elementNode = 'w:footnote';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Name of XML reference element
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $refNode = 'w:footnoteRef';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reference style name
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $refStyle = 'FootnoteReference';
|
|
|
|
|
|
2014-03-24 00:26:10 +07:00
|
|
|
/**
|
2014-04-09 21:35:55 +07:00
|
|
|
* Write word/(footnotes|endnotes).xml
|
2014-03-24 00:26:10 +07:00
|
|
|
*
|
2014-04-09 21:35:55 +07:00
|
|
|
* @param array $elements
|
2014-03-24 00:26:10 +07:00
|
|
|
*/
|
2014-04-30 08:54:38 +07:00
|
|
|
public function write($elements)
|
2014-03-22 10:06:08 +04:00
|
|
|
{
|
2014-03-30 16:31:01 +07:00
|
|
|
$xmlWriter = $this->getXmlWriter();
|
|
|
|
|
|
2014-03-22 10:06:08 +04:00
|
|
|
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
|
2014-04-30 08:54:38 +07:00
|
|
|
$xmlWriter->startElement($this->rootNode);
|
2014-04-01 15:01:30 +07:00
|
|
|
$xmlWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006');
|
|
|
|
|
$xmlWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office');
|
|
|
|
|
$xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
|
|
|
|
|
$xmlWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math');
|
|
|
|
|
$xmlWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
|
|
|
|
|
$xmlWriter->writeAttribute('xmlns:wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing');
|
|
|
|
|
$xmlWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word');
|
|
|
|
|
$xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
|
|
|
|
|
$xmlWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml');
|
|
|
|
|
|
2014-03-29 00:57:23 +07:00
|
|
|
// Separator and continuation separator
|
2014-04-30 08:54:38 +07:00
|
|
|
$xmlWriter->startElement($this->elementNode);
|
2014-04-01 15:01:30 +07:00
|
|
|
$xmlWriter->writeAttribute('w:id', -1);
|
2014-03-22 10:06:08 +04:00
|
|
|
$xmlWriter->writeAttribute('w:type', 'separator');
|
|
|
|
|
$xmlWriter->startElement('w:p');
|
|
|
|
|
$xmlWriter->startElement('w:r');
|
|
|
|
|
$xmlWriter->startElement('w:separator');
|
|
|
|
|
$xmlWriter->endElement(); // w:separator
|
|
|
|
|
$xmlWriter->endElement(); // w:r
|
|
|
|
|
$xmlWriter->endElement(); // w:p
|
2014-04-30 08:54:38 +07:00
|
|
|
$xmlWriter->endElement(); // $this->elementNode
|
|
|
|
|
$xmlWriter->startElement($this->elementNode);
|
2014-04-01 15:01:30 +07:00
|
|
|
$xmlWriter->writeAttribute('w:id', 0);
|
2014-03-22 10:06:08 +04:00
|
|
|
$xmlWriter->writeAttribute('w:type', 'continuationSeparator');
|
|
|
|
|
$xmlWriter->startElement('w:p');
|
|
|
|
|
$xmlWriter->startElement('w:r');
|
|
|
|
|
$xmlWriter->startElement('w:continuationSeparator');
|
|
|
|
|
$xmlWriter->endElement(); // w:continuationSeparator
|
|
|
|
|
$xmlWriter->endElement(); // w:r
|
|
|
|
|
$xmlWriter->endElement(); // w:p
|
2014-04-30 08:54:38 +07:00
|
|
|
$xmlWriter->endElement(); // $this->elementNode
|
2014-04-09 21:35:55 +07:00
|
|
|
|
2014-04-01 15:01:30 +07:00
|
|
|
// Content
|
2014-04-09 21:35:55 +07:00
|
|
|
foreach ($elements as $element) {
|
2014-04-30 08:54:38 +07:00
|
|
|
if ($element instanceof Footnote) {
|
|
|
|
|
$this->writeNote($xmlWriter, $element);
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|
|
|
|
|
}
|
2014-04-09 21:35:55 +07:00
|
|
|
|
2014-04-30 08:54:38 +07:00
|
|
|
$xmlWriter->endElement(); // $this->rootNode
|
2014-03-22 10:06:08 +04:00
|
|
|
|
|
|
|
|
return $xmlWriter->getData();
|
|
|
|
|
}
|
2014-03-29 00:57:23 +07:00
|
|
|
|
|
|
|
|
/**
|
2014-04-09 21:35:55 +07:00
|
|
|
* Write note item
|
2014-03-29 00:57:23 +07:00
|
|
|
*
|
2014-04-16 17:22:30 +04:00
|
|
|
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
|
|
|
|
* @param \PhpOffice\PhpWord\Element\Footnote|\PhpOffice\PhpWord\Element\Endnote $element
|
2014-03-29 00:57:23 +07:00
|
|
|
*/
|
2014-04-30 08:54:38 +07:00
|
|
|
protected function writeNote(XMLWriter $xmlWriter, $element)
|
2014-03-29 00:57:23 +07:00
|
|
|
{
|
2014-04-30 08:54:38 +07:00
|
|
|
$xmlWriter->startElement($this->elementNode);
|
2014-04-09 21:35:55 +07:00
|
|
|
$xmlWriter->writeAttribute('w:id', $element->getRelationId());
|
2014-03-29 00:57:23 +07:00
|
|
|
$xmlWriter->startElement('w:p');
|
2014-04-09 21:35:55 +07:00
|
|
|
|
2014-03-29 00:57:23 +07:00
|
|
|
// Paragraph style
|
2014-04-26 11:14:27 +07:00
|
|
|
$styleWriter = new ParagraphStyleWriter($xmlWriter, $element->getParagraphStyle());
|
|
|
|
|
$styleWriter->setIsInline(true);
|
|
|
|
|
$styleWriter->write();
|
2014-04-09 21:35:55 +07:00
|
|
|
|
2014-03-29 00:57:23 +07:00
|
|
|
// Reference symbol
|
|
|
|
|
$xmlWriter->startElement('w:r');
|
|
|
|
|
$xmlWriter->startElement('w:rPr');
|
|
|
|
|
$xmlWriter->startElement('w:rStyle');
|
2014-04-30 08:54:38 +07:00
|
|
|
$xmlWriter->writeAttribute('w:val', $this->refStyle);
|
2014-03-29 00:57:23 +07:00
|
|
|
$xmlWriter->endElement(); // w:rStyle
|
|
|
|
|
$xmlWriter->endElement(); // w:rPr
|
2014-04-30 08:54:38 +07:00
|
|
|
$xmlWriter->writeElement($this->refNode);
|
2014-03-29 00:57:23 +07:00
|
|
|
$xmlWriter->endElement(); // w:r
|
2014-04-09 21:35:55 +07:00
|
|
|
|
2014-03-29 00:57:23 +07:00
|
|
|
// Empty space after refence symbol
|
|
|
|
|
$xmlWriter->startElement('w:r');
|
|
|
|
|
$xmlWriter->startElement('w:t');
|
|
|
|
|
$xmlWriter->writeAttribute('xml:space', 'preserve');
|
|
|
|
|
$xmlWriter->writeRaw(' ');
|
|
|
|
|
$xmlWriter->endElement(); // w:t
|
|
|
|
|
$xmlWriter->endElement(); // w:r
|
2014-04-03 06:54:45 +07:00
|
|
|
|
2014-04-09 21:35:55 +07:00
|
|
|
$this->writeContainerElements($xmlWriter, $element);
|
2014-04-03 06:54:45 +07:00
|
|
|
|
2014-03-29 00:57:23 +07:00
|
|
|
$xmlWriter->endElement(); // w:p
|
2014-04-30 08:54:38 +07:00
|
|
|
$xmlWriter->endElement(); // $this->elementNode
|
2014-03-29 00:57:23 +07:00
|
|
|
}
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|