2014-04-27 10:44:26 +07: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-04-27 10:44:26 +07:00
|
|
|
*
|
|
|
|
|
* @link https://github.com/PHPOffice/PHPWord
|
2016-07-31 12:35:06 +04:00
|
|
|
* @copyright 2010-2016 PHPWord contributors
|
2014-05-04 21:03:28 +04:00
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
2014-04-27 10:44:26 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace PhpOffice\PhpWord\Reader\Word2007;
|
|
|
|
|
|
2016-01-23 19:16:34 +04:00
|
|
|
use PhpOffice\Common\XMLReader;
|
2014-05-05 23:30:15 +07:00
|
|
|
use PhpOffice\PhpWord\PhpWord;
|
|
|
|
|
|
2014-04-27 10:44:26 +07:00
|
|
|
/**
|
|
|
|
|
* Footnotes reader
|
2014-05-21 22:10:36 +07:00
|
|
|
*
|
|
|
|
|
* @since 0.10.0
|
2014-04-27 10:44:26 +07:00
|
|
|
*/
|
2014-05-05 23:30:15 +07:00
|
|
|
class Footnotes extends AbstractPart
|
2014-04-27 10:44:26 +07:00
|
|
|
{
|
|
|
|
|
/**
|
2014-05-05 23:30:15 +07:00
|
|
|
* Collection name footnotes|endnotes
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $collection = 'footnotes';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Element name footnote|endnote
|
2014-04-27 10:44:26 +07:00
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2014-05-05 23:30:15 +07:00
|
|
|
protected $element = 'footnote';
|
|
|
|
|
|
|
|
|
|
/**
|
2014-07-03 15:40:24 +04:00
|
|
|
* Read (footnotes|endnotes).xml.
|
2014-05-05 23:30:15 +07:00
|
|
|
*
|
2014-07-04 16:35:13 +04:00
|
|
|
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
2014-07-03 15:40:24 +04:00
|
|
|
* @return void
|
2014-05-05 23:30:15 +07:00
|
|
|
*/
|
2014-07-04 16:35:13 +04:00
|
|
|
public function read(PhpWord $phpWord)
|
2014-05-05 23:30:15 +07:00
|
|
|
{
|
|
|
|
|
$getMethod = "get{$this->collection}";
|
|
|
|
|
$collection = $phpWord->$getMethod()->getItems();
|
|
|
|
|
|
|
|
|
|
$xmlReader = new XMLReader();
|
|
|
|
|
$xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
|
|
|
|
|
$nodes = $xmlReader->getElements('*');
|
|
|
|
|
if ($nodes->length > 0) {
|
|
|
|
|
foreach ($nodes as $node) {
|
|
|
|
|
$id = $xmlReader->getAttribute('w:id', $node);
|
|
|
|
|
$type = $xmlReader->getAttribute('w:type', $node);
|
|
|
|
|
|
|
|
|
|
// Avoid w:type "separator" and "continuationSeparator"
|
|
|
|
|
// Only look for <footnote> or <endnote> without w:type attribute
|
2014-10-10 21:10:29 +04:00
|
|
|
if (is_null($type) && isset($collection[$id])) {
|
2014-05-05 23:30:15 +07:00
|
|
|
$element = $collection[$id];
|
|
|
|
|
$pNodes = $xmlReader->getElements('w:p/*', $node);
|
|
|
|
|
foreach ($pNodes as $pNode) {
|
|
|
|
|
$this->readRun($xmlReader, $pNode, $element, $this->collection);
|
|
|
|
|
}
|
|
|
|
|
$addMethod = "add{$this->element}";
|
|
|
|
|
$phpWord->$addMethod($element);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-27 10:44:26 +07:00
|
|
|
}
|