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
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace PhpOffice\PhpWord\Writer\Word2007;
|
|
|
|
|
|
2014-03-31 01:13:02 +07:00
|
|
|
use PhpOffice\PhpWord\Element\Footnote;
|
|
|
|
|
use PhpOffice\PhpWord\Element\Text;
|
|
|
|
|
use PhpOffice\PhpWord\Element\Link;
|
|
|
|
|
use PhpOffice\PhpWord\Element\TextBreak;
|
2014-03-29 00:57:23 +07:00
|
|
|
use PhpOffice\PhpWord\Style\Paragraph;
|
2014-03-22 10:06:08 +04:00
|
|
|
use PhpOffice\PhpWord\Shared\XMLWriter;
|
|
|
|
|
|
2014-03-24 00:26:10 +07:00
|
|
|
/**
|
|
|
|
|
* Word2007 footnotes part writer
|
|
|
|
|
*/
|
2014-03-22 10:06:08 +04:00
|
|
|
class Footnotes extends Base
|
|
|
|
|
{
|
2014-03-24 00:26:10 +07:00
|
|
|
/**
|
|
|
|
|
* Write word/footnotes.xml
|
|
|
|
|
*
|
|
|
|
|
* @param array $allFootnotesCollection
|
|
|
|
|
*/
|
2014-03-22 10:06:08 +04:00
|
|
|
public function writeFootnotes($allFootnotesCollection)
|
|
|
|
|
{
|
|
|
|
|
// Create XML writer
|
2014-03-30 16:31:01 +07:00
|
|
|
$xmlWriter = $this->getXmlWriter();
|
|
|
|
|
|
2014-03-22 10:06:08 +04:00
|
|
|
// XML header
|
|
|
|
|
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
|
|
|
|
|
$xmlWriter->startElement('w:footnotes');
|
2014-03-29 00:57:23 +07:00
|
|
|
$xmlWriter->writeAttribute(
|
|
|
|
|
'xmlns:r',
|
|
|
|
|
'http://schemas.openxmlformats.org/officeDocument/2006/relationships'
|
|
|
|
|
);
|
|
|
|
|
$xmlWriter->writeAttribute(
|
|
|
|
|
'xmlns:w',
|
|
|
|
|
'http://schemas.openxmlformats.org/wordprocessingml/2006/main'
|
|
|
|
|
);
|
|
|
|
|
// Separator and continuation separator
|
2014-03-22 10:06:08 +04:00
|
|
|
$xmlWriter->startElement('w:footnote');
|
|
|
|
|
$xmlWriter->writeAttribute('w:id', 0);
|
|
|
|
|
$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
|
|
|
|
|
$xmlWriter->endElement(); // w:footnote
|
2014-03-29 00:57:23 +07:00
|
|
|
// Content
|
2014-03-22 10:06:08 +04:00
|
|
|
$xmlWriter->startElement('w:footnote');
|
|
|
|
|
$xmlWriter->writeAttribute('w:id', 1);
|
|
|
|
|
$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
|
|
|
|
|
$xmlWriter->endElement(); // w:footnote
|
|
|
|
|
foreach ($allFootnotesCollection as $footnote) {
|
|
|
|
|
if ($footnote instanceof Footnote) {
|
2014-03-29 00:57:23 +07:00
|
|
|
$this->writeFootnote($xmlWriter, $footnote);
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$xmlWriter->endElement();
|
|
|
|
|
|
|
|
|
|
return $xmlWriter->getData();
|
|
|
|
|
}
|
2014-03-29 00:57:23 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Write footnote content, overrides method in parent class
|
|
|
|
|
*
|
2014-03-30 18:51:25 +07:00
|
|
|
* @param XMLWriter $xmlWriter
|
|
|
|
|
* @param Footnote $footnote
|
|
|
|
|
* @param boolean $withoutP
|
2014-03-29 00:57:23 +07:00
|
|
|
*/
|
2014-03-30 18:51:25 +07:00
|
|
|
protected function writeFootnote(XMLWriter $xmlWriter, Footnote $footnote, $withoutP = false)
|
2014-03-29 00:57:23 +07:00
|
|
|
{
|
|
|
|
|
$xmlWriter->startElement('w:footnote');
|
|
|
|
|
$xmlWriter->writeAttribute('w:id', $footnote->getReferenceId());
|
|
|
|
|
$xmlWriter->startElement('w:p');
|
|
|
|
|
// Paragraph style
|
2014-03-30 18:51:25 +07:00
|
|
|
$styleParagraph = $footnote->getParagraphStyle();
|
|
|
|
|
$this->writeInlineParagraphStyle($xmlWriter, $styleParagraph);
|
2014-03-29 00:57:23 +07:00
|
|
|
// Reference symbol
|
|
|
|
|
$xmlWriter->startElement('w:r');
|
|
|
|
|
$xmlWriter->startElement('w:rPr');
|
|
|
|
|
$xmlWriter->startElement('w:rStyle');
|
|
|
|
|
$xmlWriter->writeAttribute('w:val', 'FootnoteReference');
|
|
|
|
|
$xmlWriter->endElement(); // w:rStyle
|
|
|
|
|
$xmlWriter->endElement(); // w:rPr
|
|
|
|
|
$xmlWriter->writeElement('w:footnoteRef');
|
|
|
|
|
$xmlWriter->endElement(); // w:r
|
|
|
|
|
// 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
|
|
|
|
|
// Actual footnote contents
|
|
|
|
|
$elements = $footnote->getElements();
|
|
|
|
|
if (count($elements) > 0) {
|
|
|
|
|
foreach ($elements as $element) {
|
|
|
|
|
if ($element instanceof Text) {
|
2014-03-30 18:51:25 +07:00
|
|
|
$this->writeText($xmlWriter, $element, true);
|
2014-03-29 00:57:23 +07:00
|
|
|
} elseif ($element instanceof Link) {
|
2014-03-30 18:51:25 +07:00
|
|
|
$this->writeLink($xmlWriter, $element, true);
|
2014-03-29 00:57:23 +07:00
|
|
|
} elseif ($element instanceof TextBreak) {
|
|
|
|
|
$xmlWriter->writeElement('w:br');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$xmlWriter->endElement(); // w:p
|
|
|
|
|
$xmlWriter->endElement(); // w:footnote
|
|
|
|
|
}
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|