2014-03-22 10:06:08 +04:00
|
|
|
<?php
|
|
|
|
|
/**
|
2014-05-05 13:06:53 +04:00
|
|
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
|
|
|
|
* word processing documents.
|
|
|
|
|
*
|
|
|
|
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
|
|
|
|
* General Public License version 3 as published by the Free Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* For the full copyright and license information, please read the LICENSE
|
|
|
|
|
* file that was distributed with this source code. For the full list of
|
|
|
|
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
2014-03-22 10:06:08 +04:00
|
|
|
*
|
2017-11-04 22:44:12 +01:00
|
|
|
* @see https://github.com/PHPOffice/PHPWord
|
|
|
|
|
* @copyright 2010-2017 PHPWord contributors
|
2014-05-04 21:03:28 +04:00
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
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
|
|
|
|
2016-01-23 19:16:34 +04:00
|
|
|
use PhpOffice\Common\XMLWriter;
|
2014-03-31 01:13:02 +07:00
|
|
|
use PhpOffice\PhpWord\Element\Footnote;
|
2014-05-07 09:47:02 +07:00
|
|
|
use PhpOffice\PhpWord\Writer\Word2007\Element\Container;
|
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
|
|
|
/**
|
2014-05-06 08:50:55 +07:00
|
|
|
* Word2007 footnotes part writer: word/(footnotes|endnotes).xml
|
2014-03-24 00:26:10 +07:00
|
|
|
*/
|
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-05-06 08:50:55 +07:00
|
|
|
* Footnotes/endnotes collection to be written
|
2014-03-24 00:26:10 +07:00
|
|
|
*
|
2014-05-06 08:50:55 +07:00
|
|
|
* @var \PhpOffice\PhpWord\Collection\Footnotes|\PhpOffice\PhpWord\Collection\Endnotes
|
2014-03-24 00:26:10 +07:00
|
|
|
*/
|
2014-05-06 08:50:55 +07:00
|
|
|
protected $elements;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Write part
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function write()
|
2014-03-22 10:06:08 +04:00
|
|
|
{
|
2014-03-30 16:31:01 +07:00
|
|
|
$xmlWriter = $this->getXmlWriter();
|
2014-05-06 08:50:55 +07:00
|
|
|
$drawingSchema = 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing';
|
2014-03-30 16:31:01 +07:00
|
|
|
|
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');
|
2014-05-06 08:50:55 +07:00
|
|
|
$xmlWriter->writeAttribute('xmlns:wp', $drawingSchema);
|
2014-04-01 15:01:30 +07:00
|
|
|
$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-05-14 19:41:44 +07:00
|
|
|
/** @var array $elements Type hint */
|
2014-05-12 14:24:13 +07:00
|
|
|
$elements = $this->elements;
|
|
|
|
|
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-05-06 08:50:55 +07:00
|
|
|
/**
|
|
|
|
|
* Set element
|
|
|
|
|
*
|
|
|
|
|
* @param \PhpOffice\PhpWord\Collection\Footnotes|\PhpOffice\PhpWord\Collection\Endnotes $elements
|
|
|
|
|
* @return self
|
|
|
|
|
*/
|
|
|
|
|
public function setElements($elements)
|
|
|
|
|
{
|
|
|
|
|
$this->elements = $elements;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-29 00:57:23 +07:00
|
|
|
/**
|
2014-07-03 15:40:24 +04:00
|
|
|
* Write note item.
|
2014-03-29 00:57:23 +07:00
|
|
|
*
|
2016-01-23 19:16:34 +04:00
|
|
|
* @param \PhpOffice\Common\XMLWriter $xmlWriter
|
2014-04-16 17:22:30 +04:00
|
|
|
* @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');
|
2016-06-04 20:06:37 +04:00
|
|
|
$xmlWriter->text(' ');
|
2014-03-29 00:57:23 +07:00
|
|
|
$xmlWriter->endElement(); // w:t
|
|
|
|
|
$xmlWriter->endElement(); // w:r
|
2014-04-03 06:54:45 +07:00
|
|
|
|
2014-05-07 09:47:02 +07:00
|
|
|
$containerWriter = new Container($xmlWriter, $element);
|
|
|
|
|
$containerWriter->write();
|
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
|
|
|
}
|