Reader: Ability to read header, footer, footnotes, link, preservetext, textbreak, pagebreak, table
This commit is contained in:
parent
6456255300
commit
2cdad4b247
|
|
@ -25,10 +25,9 @@ This release marked heavy refactorings on internal code structure with the creat
|
|||
- CheckBox: Ability to add checkbox in header/footer - @ivanlanin GH-187
|
||||
- Link: Ability to add link in header/footer - @ivanlanin GH-187
|
||||
- Object: Ability to add object in header, footer, textrun, and footnote - @ivanlanin GH-187
|
||||
- Media: Add `Media::reset()` to reset all media data - @juzi GH-19
|
||||
- Style: Add `Style::reset()` to reset all styles
|
||||
- Footnote: Add `Footnote::reset()` to reset all footnotes
|
||||
- TOC: Add `TOC::reset()` to reset all TOC
|
||||
- Media: Add `Media::resetElements()` to reset all media data - @juzi GH-19
|
||||
- General: Add `Style::resetStyles()`, `Footnote::resetElements()`, and `TOC::resetTitles()` - @ivanlanin GH-187
|
||||
- Reader: Ability to read header, footer, footnotes, link, preservetext, textbreak, pagebreak, table - @ivanlanin
|
||||
|
||||
### Bugfixes
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -138,7 +138,7 @@ class DocumentProperties
|
|||
* Set Creator
|
||||
*
|
||||
* @param string $pValue
|
||||
* @return \PhpOffice\PhpWord\DocumentProperties
|
||||
* @return self
|
||||
*/
|
||||
public function setCreator($pValue = '')
|
||||
{
|
||||
|
|
@ -160,7 +160,7 @@ class DocumentProperties
|
|||
* Set Last Modified By
|
||||
*
|
||||
* @param string $pValue
|
||||
* @return \PhpOffice\PhpWord\DocumentProperties
|
||||
* @return self
|
||||
*/
|
||||
public function setLastModifiedBy($pValue = '')
|
||||
{
|
||||
|
|
@ -182,7 +182,7 @@ class DocumentProperties
|
|||
* Set Created
|
||||
*
|
||||
* @param int $pValue
|
||||
* @return \PhpOffice\PhpWord\DocumentProperties
|
||||
* @return self
|
||||
*/
|
||||
public function setCreated($pValue = null)
|
||||
{
|
||||
|
|
@ -207,7 +207,7 @@ class DocumentProperties
|
|||
* Set Modified
|
||||
*
|
||||
* @param int $pValue
|
||||
* @return \PhpOffice\PhpWord\DocumentProperties
|
||||
* @return self
|
||||
*/
|
||||
public function setModified($pValue = null)
|
||||
{
|
||||
|
|
@ -232,7 +232,7 @@ class DocumentProperties
|
|||
* Set Title
|
||||
*
|
||||
* @param string $pValue
|
||||
* @return \PhpOffice\PhpWord\DocumentProperties
|
||||
* @return self
|
||||
*/
|
||||
public function setTitle($pValue = '')
|
||||
{
|
||||
|
|
@ -254,7 +254,7 @@ class DocumentProperties
|
|||
* Set Description
|
||||
*
|
||||
* @param string $pValue
|
||||
* @return \PhpOffice\PhpWord\DocumentProperties
|
||||
* @return self
|
||||
*/
|
||||
public function setDescription($pValue = '')
|
||||
{
|
||||
|
|
@ -276,7 +276,7 @@ class DocumentProperties
|
|||
* Set Subject
|
||||
*
|
||||
* @param string $pValue
|
||||
* @return \PhpOffice\PhpWord\DocumentProperties
|
||||
* @return self
|
||||
*/
|
||||
public function setSubject($pValue = '')
|
||||
{
|
||||
|
|
@ -298,7 +298,7 @@ class DocumentProperties
|
|||
* Set Keywords
|
||||
*
|
||||
* @param string $pValue
|
||||
* @return \PhpOffice\PhpWord\DocumentProperties
|
||||
* @return self
|
||||
*/
|
||||
public function setKeywords($pValue = '')
|
||||
{
|
||||
|
|
@ -320,7 +320,7 @@ class DocumentProperties
|
|||
* Set Category
|
||||
*
|
||||
* @param string $pValue
|
||||
* @return \PhpOffice\PhpWord\DocumentProperties
|
||||
* @return self
|
||||
*/
|
||||
public function setCategory($pValue = '')
|
||||
{
|
||||
|
|
@ -342,7 +342,7 @@ class DocumentProperties
|
|||
* Set Company
|
||||
*
|
||||
* @param string $pValue
|
||||
* @return \PhpOffice\PhpWord\DocumentProperties
|
||||
* @return self
|
||||
*/
|
||||
public function setCompany($pValue = '')
|
||||
{
|
||||
|
|
@ -364,7 +364,7 @@ class DocumentProperties
|
|||
* Set Manager
|
||||
*
|
||||
* @param string $pValue
|
||||
* @return \PhpOffice\PhpWord\DocumentProperties
|
||||
* @return self
|
||||
*/
|
||||
public function setManager($pValue = '')
|
||||
{
|
||||
|
|
@ -432,7 +432,7 @@ class DocumentProperties
|
|||
* 's': String
|
||||
* 'd': Date/Time
|
||||
* 'b': Boolean
|
||||
* @return \PhpOffice\PhpWord\DocumentProperties
|
||||
* @return self
|
||||
*/
|
||||
public function setCustomProperty($propertyName, $propertyValue = '', $propertyType = null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ abstract class AbstractElement
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
private $docPart = 'section';
|
||||
protected $docPart = 'section';
|
||||
|
||||
/**
|
||||
* Document part Id
|
||||
|
|
@ -70,7 +70,7 @@ abstract class AbstractElement
|
|||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $docPartId = 1;
|
||||
protected $docPartId = 1;
|
||||
|
||||
/**
|
||||
* Elements collection
|
||||
|
|
@ -84,7 +84,7 @@ abstract class AbstractElement
|
|||
*
|
||||
* @var int
|
||||
*/
|
||||
private $relationId;
|
||||
protected $relationId;
|
||||
|
||||
/**
|
||||
* Add text element
|
||||
|
|
@ -144,8 +144,8 @@ abstract class AbstractElement
|
|||
|
||||
$link = new Link(String::toUTF8($linkSrc), String::toUTF8($linkName), $fontStyle, $paragraphStyle);
|
||||
$link->setDocPart($this->getDocPart(), $this->getDocPartId());
|
||||
$rID = Media::addElement($elementDocPart, 'link', $linkSrc);
|
||||
$link->setRelationId($rID);
|
||||
$rId = Media::addElement($elementDocPart, 'link', $linkSrc);
|
||||
$link->setRelationId($rId);
|
||||
$this->elements[] = $link;
|
||||
|
||||
return $link;
|
||||
|
|
@ -271,8 +271,8 @@ abstract class AbstractElement
|
|||
|
||||
$image = new Image($src, $style, $isWatermark);
|
||||
$image->setDocPart($this->getDocPart(), $this->getDocPartId());
|
||||
$rID = Media::addElement($elementDocPart, 'image', $src, $image);
|
||||
$image->setRelationId($rID);
|
||||
$rId = Media::addElement($elementDocPart, 'image', $src, $image);
|
||||
$image->setRelationId($rId);
|
||||
$this->elements[] = $image;
|
||||
return $image;
|
||||
}
|
||||
|
|
@ -301,10 +301,10 @@ abstract class AbstractElement
|
|||
$ext = substr($ext, 0, -1);
|
||||
}
|
||||
$icon = realpath(__DIR__ . "/../_staticDocParts/_{$ext}.png");
|
||||
$rID = Media::addElement($elementDocPart, 'object', $src);
|
||||
$object->setRelationId($rID);
|
||||
$rIDimg = Media::addElement($elementDocPart, 'image', $icon, new Image($icon));
|
||||
$object->setImageRelationId($rIDimg);
|
||||
$rId = Media::addElement($elementDocPart, 'object', $src);
|
||||
$object->setRelationId($rId);
|
||||
$rIdimg = Media::addElement($elementDocPart, 'image', $icon, new Image($icon));
|
||||
$object->setImageRelationId($rIdimg);
|
||||
$this->elements[] = $object;
|
||||
return $object;
|
||||
} else {
|
||||
|
|
@ -323,9 +323,10 @@ abstract class AbstractElement
|
|||
$this->checkValidity('footnote');
|
||||
|
||||
$footnote = new FootnoteElement($paragraphStyle);
|
||||
$refID = FootnoteCollection::addFootnoteElement($footnote);
|
||||
$rId = FootnoteCollection::addFootnoteElement($footnote);
|
||||
|
||||
$footnote->setDocPart('footnote', $this->getDocPartId());
|
||||
$footnote->setRelationId($refID);
|
||||
$footnote->setRelationId($rId);
|
||||
$this->elements[] = $footnote;
|
||||
|
||||
return $footnote;
|
||||
|
|
|
|||
|
|
@ -59,12 +59,12 @@ class Footnote extends AbstractElement
|
|||
/**
|
||||
* Set Footnote Reference ID
|
||||
*
|
||||
* @param int $refId
|
||||
* @param int $rId
|
||||
* @deprecated 0.9.2
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function setReferenceId($refId)
|
||||
public function setReferenceId($rId)
|
||||
{
|
||||
$this->setRelationId($refId);
|
||||
$this->setRelationId($rId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,8 +80,8 @@ class Image extends AbstractElement
|
|||
* @param string $source
|
||||
* @param mixed $style
|
||||
* @param boolean $isWatermark
|
||||
* @throws \PhpOffice\PhpWord\Exception\InvalidImageException
|
||||
* @throws \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException
|
||||
* @throws InvalidImageException
|
||||
* @throws UnsupportedImageTypeException
|
||||
*/
|
||||
public function __construct($source, $style = null, $isWatermark = false)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
namespace PhpOffice\PhpWord\Element;
|
||||
|
||||
use PhpOffice\PhpWord\Element\Text;
|
||||
use PhpOffice\PhpWord\Style\ListItem as ListItemStyle;
|
||||
|
||||
/**
|
||||
|
|
@ -26,7 +27,7 @@ class ListItem extends AbstractElement
|
|||
/**
|
||||
* Textrun
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Element\Text
|
||||
* @var Text
|
||||
*/
|
||||
private $textObject;
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class Object extends AbstractElement
|
|||
/**
|
||||
* Image Style
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Style\Image
|
||||
* @var ImageStyle
|
||||
*/
|
||||
private $style;
|
||||
|
||||
|
|
@ -60,7 +60,7 @@ class Object extends AbstractElement
|
|||
/**
|
||||
* Get Image style
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\Image
|
||||
* @return ImageStyle
|
||||
*/
|
||||
public function getStyle()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
namespace PhpOffice\PhpWord\Element;
|
||||
|
||||
use PhpOffice\PhpWord\Element\Row;
|
||||
use PhpOffice\PhpWord\Element\Cell;
|
||||
use PhpOffice\PhpWord\Style\Table as TableStyle;
|
||||
|
||||
/**
|
||||
|
|
@ -70,7 +71,7 @@ class Table extends AbstractElement
|
|||
*
|
||||
* @param int $width
|
||||
* @param mixed $style
|
||||
* @return \PhpOffice\PhpWord\Element\Cell
|
||||
* @return Cell
|
||||
*/
|
||||
public function addCell($width = null, $style = null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,65 +13,133 @@ use PhpOffice\PhpWord\Media;
|
|||
use PhpOffice\PhpWord\Element\Footnote as FootnoteElement;
|
||||
|
||||
/**
|
||||
* Footnote
|
||||
* Footnote collection
|
||||
*/
|
||||
class Footnote
|
||||
{
|
||||
/**
|
||||
* Footnote elements
|
||||
* Elements
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $elements = array();
|
||||
|
||||
/**
|
||||
* Add new element
|
||||
*
|
||||
* @param FootnoteElement $footnote
|
||||
* @return integer Reference ID
|
||||
* @since 0.9.2
|
||||
*/
|
||||
public static function addElement(FootnoteElement $footnote)
|
||||
{
|
||||
$rId = self::countElements() + 1;
|
||||
self::$elements[$rId] = $footnote;
|
||||
|
||||
return $rId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set element
|
||||
*
|
||||
* @param integer $index
|
||||
* @param FootnoteElement $footnote
|
||||
* @since 0.9.2
|
||||
*/
|
||||
public static function setElement($index, FootnoteElement $footnote)
|
||||
{
|
||||
self::$elements[$index] = $footnote;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get element by index
|
||||
*
|
||||
* @return FootnoteElement
|
||||
* @since 0.9.2
|
||||
*/
|
||||
public static function getElement($index)
|
||||
{
|
||||
if (array_key_exists($index, self::$elements)) {
|
||||
return self::$elements[$index];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get elements
|
||||
*
|
||||
* @return array
|
||||
* @since 0.9.2
|
||||
*/
|
||||
public static function getElements()
|
||||
{
|
||||
return self::$elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get element count
|
||||
*
|
||||
* @return integer
|
||||
* @since 0.9.2
|
||||
*/
|
||||
public static function countElements()
|
||||
{
|
||||
return count(self::$elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset elements
|
||||
*
|
||||
* @since 0.9.2
|
||||
*/
|
||||
public static function resetElements()
|
||||
{
|
||||
self::$elements = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new footnote
|
||||
*
|
||||
* @param FootnoteElement $footnote
|
||||
* @return int Reference ID
|
||||
* @return integer Reference ID
|
||||
* @deprecated 0.9.2
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function addFootnoteElement(FootnoteElement $footnote)
|
||||
{
|
||||
$refID = self::countFootnoteElements() + 1;
|
||||
|
||||
self::$elements[] = $footnote;
|
||||
|
||||
return $refID;
|
||||
return self::addElement($footnote);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Footnote Elements
|
||||
*
|
||||
* @return array
|
||||
* @deprecated 0.9.2
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function getFootnoteElements()
|
||||
{
|
||||
return self::$elements;
|
||||
return self::getElements();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Footnote Elements Count
|
||||
*
|
||||
* @return int
|
||||
* @return integer
|
||||
* @deprecated 0.9.2
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function countFootnoteElements()
|
||||
{
|
||||
return count(self::$elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset footer elements
|
||||
*/
|
||||
public static function reset()
|
||||
{
|
||||
self::$elements = array();
|
||||
return self::countElements();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new Footnote Link Element
|
||||
*
|
||||
* @param string $linkSrc
|
||||
* @return int Reference ID
|
||||
* @return integer Reference ID
|
||||
* @deprecated 0.9.2
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@
|
|||
namespace PhpOffice\PhpWord;
|
||||
|
||||
use PhpOffice\PhpWord\Exception\Exception;
|
||||
use PhpOffice\PhpWord\Writer\WriterInterface;
|
||||
use PhpOffice\PhpWord\Reader\ReaderInterface;
|
||||
|
||||
/**
|
||||
* IO factory
|
||||
|
|
@ -19,9 +21,9 @@ abstract class IOFactory
|
|||
/**
|
||||
* Create new writer
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
||||
* @param PhpWord $phpWord
|
||||
* @param string $name
|
||||
* @return \PhpOffice\PhpWord\Writer\WriterInterface
|
||||
* @return WriterInterface
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function createWriter(PhpWord $phpWord, $name = 'Word2007')
|
||||
|
|
@ -38,7 +40,7 @@ abstract class IOFactory
|
|||
* Create new reader
|
||||
*
|
||||
* @param string $name
|
||||
* @return \PhpOffice\PhpWord\Reader\ReaderInterface
|
||||
* @return ReaderInterface
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function createReader($name = 'Word2007')
|
||||
|
|
@ -56,7 +58,7 @@ abstract class IOFactory
|
|||
*
|
||||
* @param string $filename The name of the file
|
||||
* @param string $readerName
|
||||
* @return \PhpOffice\PhpWord
|
||||
* @return PhpWord
|
||||
*/
|
||||
public static function load($filename, $readerName = 'Word2007')
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use PhpOffice\PhpWord\Exception\Exception;
|
|||
use PhpOffice\PhpWord\Element\Image;
|
||||
|
||||
/**
|
||||
* Media
|
||||
* Media collection
|
||||
*/
|
||||
class Media
|
||||
{
|
||||
|
|
@ -39,7 +39,7 @@ class Media
|
|||
// Assign unique media Id and initiate media container if none exists
|
||||
$mediaId = md5($container . $source);
|
||||
if (!array_key_exists($container, self::$elements)) {
|
||||
self::$elements[$container]= array();
|
||||
self::$elements[$container] = array();
|
||||
}
|
||||
|
||||
// Add media if not exists or point to existing media
|
||||
|
|
@ -47,7 +47,7 @@ class Media
|
|||
$mediaCount = self::countElements($container);
|
||||
$mediaTypeCount = self::countElements($container, $mediaType);
|
||||
$mediaData = array();
|
||||
$relId = ++$mediaCount;
|
||||
$rId = ++$mediaCount;
|
||||
$target = null;
|
||||
$mediaTypeCount++;
|
||||
|
||||
|
|
@ -57,15 +57,15 @@ class Media
|
|||
throw new Exception('Image object not assigned.');
|
||||
}
|
||||
$isMemImage = $image->getIsMemImage();
|
||||
$ext = $image->getImageExtension();
|
||||
$mediaData['imageExtension'] = $ext;
|
||||
$extension = $image->getImageExtension();
|
||||
$mediaData['imageExtension'] = $extension;
|
||||
$mediaData['imageType'] = $image->getImageType();
|
||||
if ($isMemImage) {
|
||||
$mediaData['isMemImage'] = true;
|
||||
$mediaData['createFunction'] = $image->getImageCreateFunction();
|
||||
$mediaData['imageFunction'] = $image->getImageFunction();
|
||||
}
|
||||
$target = "media/{$container}_image{$mediaTypeCount}.{$ext}";
|
||||
$target = "media/{$container}_image{$mediaTypeCount}.{$extension}";
|
||||
// Objects
|
||||
} elseif ($mediaType == 'object') {
|
||||
$file = "oleObject{$mediaTypeCount}.bin";
|
||||
|
|
@ -78,9 +78,9 @@ class Media
|
|||
$mediaData['source'] = $source;
|
||||
$mediaData['target'] = $target;
|
||||
$mediaData['type'] = $mediaType;
|
||||
$mediaData['rID'] = $relId;
|
||||
$mediaData['rID'] = $rId;
|
||||
self::$elements[$container][$mediaId] = $mediaData;
|
||||
return $relId;
|
||||
return $rId;
|
||||
} else {
|
||||
return self::$elements[$container][$mediaId]['rID'];
|
||||
}
|
||||
|
|
@ -153,7 +153,7 @@ class Media
|
|||
/**
|
||||
* Reset media elements
|
||||
*/
|
||||
public static function reset()
|
||||
public static function resetElements()
|
||||
{
|
||||
self::$elements = array();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,8 +82,8 @@ class PhpWord
|
|||
/**
|
||||
* Set document properties object
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\DocumentProperties $documentProperties
|
||||
* @return \PhpOffice\PhpWord\PhpWord
|
||||
* @param DocumentProperties $documentProperties
|
||||
* @return self
|
||||
*/
|
||||
public function setDocumentProperties(DocumentProperties $documentProperties)
|
||||
{
|
||||
|
|
@ -217,7 +217,7 @@ class PhpWord
|
|||
/**
|
||||
* Get all sections
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Element\Section[]
|
||||
* @return Section[]
|
||||
*/
|
||||
public function getSections()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ abstract class AbstractReader implements ReaderInterface
|
|||
* Set read data only
|
||||
*
|
||||
* @param bool $pValue
|
||||
* @return \PhpOffice\PhpWord\Reader\ReaderInterface
|
||||
* @return self
|
||||
*/
|
||||
public function setReadDataOnly($pValue = true)
|
||||
{
|
||||
|
|
@ -60,7 +60,7 @@ abstract class AbstractReader implements ReaderInterface
|
|||
*
|
||||
* @param string $pFilename
|
||||
* @return resource
|
||||
* @throws \PhpOffice\PhpWord\Exception\Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function openFile($pFilename)
|
||||
{
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -38,7 +38,7 @@ class XMLReader
|
|||
*
|
||||
* @param string $zipFile
|
||||
* @param string $xmlFile
|
||||
* @return \DOMDocument
|
||||
* @return \DOMDocument|false
|
||||
*/
|
||||
public function getDomFromZip($zipFile, $xmlFile)
|
||||
{
|
||||
|
|
@ -54,6 +54,7 @@ class XMLReader
|
|||
}
|
||||
$contents = $zip->getFromName($xmlFile);
|
||||
$zip->close();
|
||||
|
||||
if ($contents === false) {
|
||||
return false;
|
||||
} else {
|
||||
|
|
@ -69,7 +70,7 @@ class XMLReader
|
|||
* @param string $path
|
||||
* @return \DOMNodeList
|
||||
*/
|
||||
public function getElements($path, \DOMNode $context = null)
|
||||
public function getElements($path, \DOMNode $contextNode = null)
|
||||
{
|
||||
if ($this->dom === null) {
|
||||
return array();
|
||||
|
|
@ -78,42 +79,42 @@ class XMLReader
|
|||
$this->xpath = new \DOMXpath($this->dom);
|
||||
}
|
||||
|
||||
return $this->xpath->query($path, $context);
|
||||
return $this->xpath->query($path, $contextNode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get elements
|
||||
* Get element
|
||||
*
|
||||
* @param string $path
|
||||
* @return \DOMNodeList
|
||||
* @return \DOMNode|null
|
||||
*/
|
||||
public function getElement($path, \DOMNode $context = null)
|
||||
public function getElement($path, \DOMNode $contextNode)
|
||||
{
|
||||
$elements = $this->getElements($path, $context);
|
||||
$elements = $this->getElements($path, $contextNode);
|
||||
if ($elements->length > 0) {
|
||||
return $elements->item(0);
|
||||
} else {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get element attribute
|
||||
*
|
||||
* @param string|\DOMNode $path
|
||||
* @param string $attribute
|
||||
* @return null|string
|
||||
* @param string $path
|
||||
* @return string|null
|
||||
*/
|
||||
public function getAttribute($path, $attribute, \DOMNode $context = null)
|
||||
public function getAttribute($attribute, \DOMElement $contextNode, $path = null)
|
||||
{
|
||||
if ($path instanceof \DOMNode) {
|
||||
$return = $path->getAttribute($attribute);
|
||||
if (is_null($path)) {
|
||||
$return = $contextNode->getAttribute($attribute);
|
||||
} else {
|
||||
$elements = $this->getElements($path, $context);
|
||||
$elements = $this->getElements($path, $contextNode);
|
||||
if ($elements->length > 0) {
|
||||
$return = $elements->item(0)->getAttribute($attribute);
|
||||
} else {
|
||||
$return = '';
|
||||
$return = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -124,29 +125,28 @@ class XMLReader
|
|||
* Get element value
|
||||
*
|
||||
* @param string $path
|
||||
* @return null|string
|
||||
* @return string|null
|
||||
*/
|
||||
public function getValue($path, \DOMNode $context = null)
|
||||
public function getValue($path, \DOMNode $contextNode)
|
||||
{
|
||||
$elements = $this->getElements($path, $context);
|
||||
$elements = $this->getElements($path, $contextNode);
|
||||
if ($elements->length > 0) {
|
||||
$return = $elements->item(0)->nodeValue;
|
||||
return $elements->item(0)->nodeValue;
|
||||
} else {
|
||||
$return = '';
|
||||
return null;
|
||||
}
|
||||
|
||||
return ($return == '') ? null : $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count elements
|
||||
*
|
||||
* @param string $path
|
||||
* @return \DOMNodeList
|
||||
* @return integer
|
||||
*/
|
||||
public function countElements($path, \DOMNode $context = null)
|
||||
public function countElements($path, \DOMNode $contextNode)
|
||||
{
|
||||
$elements = $this->getElements($path, $context);
|
||||
$elements = $this->getElements($path, $contextNode);
|
||||
|
||||
return $elements->length;
|
||||
}
|
||||
|
||||
|
|
@ -156,8 +156,8 @@ class XMLReader
|
|||
* @param string $path
|
||||
* @return \DOMNodeList
|
||||
*/
|
||||
public function elementExists($path, \DOMNode $context = null)
|
||||
public function elementExists($path, \DOMNode $contextNode)
|
||||
{
|
||||
return $this->getElements($path, $context)->length > 0;
|
||||
return $this->getElements($path, $contextNode)->length > 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,13 @@ class ZipArchive
|
|||
const OVERWRITE = 'OVERWRITE';
|
||||
const CREATE = 'CREATE';
|
||||
|
||||
/**
|
||||
* Number of files (emulate ZipArchive::$numFiles)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $numFiles = 0;
|
||||
|
||||
/**
|
||||
* Temporary storage directory
|
||||
*
|
||||
|
|
@ -48,13 +55,14 @@ class ZipArchive
|
|||
/**
|
||||
* Open a new zip archive
|
||||
*
|
||||
* @param string $fileName Filename for the zip archive
|
||||
* @param string $filename Filename for the zip archive
|
||||
* @return boolean
|
||||
*/
|
||||
public function open($fileName)
|
||||
public function open($filename)
|
||||
{
|
||||
$this->tempDir = sys_get_temp_dir();
|
||||
$this->zip = new \PclZip($fileName);
|
||||
$this->zip = new \PclZip($filename);
|
||||
$this->numFiles = count($this->zip->listContent());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -138,19 +146,19 @@ class ZipArchive
|
|||
}
|
||||
|
||||
/**
|
||||
* Find if given fileName exist in archive (Emulate ZipArchive locateName())
|
||||
* Find if given file name exist in archive (Emulate ZipArchive locateName())
|
||||
*
|
||||
* @param string $fileName Filename for the file in zip archive
|
||||
* @param string $filename Filename for the file in zip archive
|
||||
* @return boolean
|
||||
*/
|
||||
public function locateName($fileName)
|
||||
public function locateName($filename)
|
||||
{
|
||||
$list = $this->zip->listContent();
|
||||
$listCount = count($list);
|
||||
$listIndex = -1;
|
||||
for ($i = 0; $i < $listCount; ++$i) {
|
||||
if (strtolower($list[$i]["filename"]) == strtolower($fileName) ||
|
||||
strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) {
|
||||
if (strtolower($list[$i]["filename"]) == strtolower($filename) ||
|
||||
strtolower($list[$i]["stored_filename"]) == strtolower($filename)) {
|
||||
$listIndex = $i;
|
||||
break;
|
||||
}
|
||||
|
|
@ -160,12 +168,12 @@ class ZipArchive
|
|||
}
|
||||
|
||||
/**
|
||||
* Extract file from archive by given fileName (Emulate ZipArchive getFromName())
|
||||
* Extract file from archive by given file name (Emulate ZipArchive getFromName())
|
||||
*
|
||||
* @param string $fileName Filename for the file in zip archive
|
||||
* @param string $filename Filename for the file in zip archive
|
||||
* @return string $contents File string contents
|
||||
*/
|
||||
public function getFromName($fileName)
|
||||
public function getFromName($filename)
|
||||
{
|
||||
$list = $this->zip->listContent();
|
||||
$listCount = count($list);
|
||||
|
|
@ -173,8 +181,8 @@ class ZipArchive
|
|||
$contents = null;
|
||||
|
||||
for ($i = 0; $i < $listCount; ++$i) {
|
||||
if (strtolower($list[$i]["filename"]) == strtolower($fileName) ||
|
||||
strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) {
|
||||
if (strtolower($list[$i]["filename"]) == strtolower($filename) ||
|
||||
strtolower($list[$i]["stored_filename"]) == strtolower($filename)) {
|
||||
$listIndex = $i;
|
||||
break;
|
||||
}
|
||||
|
|
@ -183,11 +191,11 @@ class ZipArchive
|
|||
if ($listIndex != -1) {
|
||||
$extracted = $this->zip->extractByIndex($listIndex, PCLZIP_OPT_EXTRACT_AS_STRING);
|
||||
} else {
|
||||
$fileName = substr($fileName, 1);
|
||||
$filename = substr($filename, 1);
|
||||
$listIndex = -1;
|
||||
for ($i = 0; $i < $listCount; ++$i) {
|
||||
if (strtolower($list[$i]["filename"]) == strtolower($fileName) ||
|
||||
strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) {
|
||||
if (strtolower($list[$i]["filename"]) == strtolower($filename) ||
|
||||
strtolower($list[$i]["stored_filename"]) == strtolower($filename)) {
|
||||
$listIndex = $i;
|
||||
break;
|
||||
}
|
||||
|
|
@ -200,4 +208,21 @@ class ZipArchive
|
|||
|
||||
return $contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of an entry using its index
|
||||
*
|
||||
* @param integer $index
|
||||
* @return string|false
|
||||
*/
|
||||
public function getNameIndex($index)
|
||||
{
|
||||
$list = $this->zip->listContent();
|
||||
$listCount = count($list);
|
||||
if ($index <= $listCount) {
|
||||
return $list[$index]['filename'];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ use PhpOffice\PhpWord\Style\Paragraph;
|
|||
use PhpOffice\PhpWord\Style\Table;
|
||||
|
||||
/**
|
||||
* Style
|
||||
* Style collection
|
||||
*/
|
||||
class Style
|
||||
{
|
||||
|
|
@ -91,7 +91,7 @@ class Style
|
|||
/**
|
||||
* Reset styles
|
||||
*/
|
||||
public static function reset()
|
||||
public static function resetStyles()
|
||||
{
|
||||
self::$styles = array();
|
||||
}
|
||||
|
|
@ -109,7 +109,7 @@ class Style
|
|||
/**
|
||||
* Get all styles
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\Font[]
|
||||
* @return Font[]
|
||||
*/
|
||||
public static function getStyles()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -152,9 +152,9 @@ class TOC
|
|||
}
|
||||
|
||||
/**
|
||||
* Reset footnotes
|
||||
* Reset titles
|
||||
*/
|
||||
public static function reset()
|
||||
public static function resetTitles()
|
||||
{
|
||||
self::$titles = array();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ use PhpOffice\PhpWord\Exception\Exception;
|
|||
use PhpOffice\PhpWord\PhpWord;
|
||||
use PhpOffice\PhpWord\Footnote;
|
||||
use PhpOffice\PhpWord\Media;
|
||||
use PhpOffice\PhpWord\Element\Section;
|
||||
use PhpOffice\PhpWord\Writer\Word2007\ContentTypes;
|
||||
use PhpOffice\PhpWord\Writer\Word2007\Rels;
|
||||
use PhpOffice\PhpWord\Writer\Word2007\DocProps;
|
||||
|
|
@ -97,11 +98,11 @@ class Word2007 extends AbstractWriter implements WriterInterface
|
|||
|
||||
// Add header/footer contents
|
||||
$overrides = array();
|
||||
$rID = Media::countElements('section') + 6; // @see Rels::writeDocRels for 6 first elements
|
||||
$rId = Media::countElements('section') + 6; // @see Rels::writeDocRels for 6 first elements
|
||||
$sections = $this->phpWord->getSections();
|
||||
foreach ($sections as $section) {
|
||||
$this->addHeaderFooterContent($section, $objZip, 'header', $rID);
|
||||
$this->addHeaderFooterContent($section, $objZip, 'footer', $rID);
|
||||
$this->addHeaderFooterContent($section, $objZip, 'header', $rId);
|
||||
$this->addHeaderFooterContent($section, $objZip, 'footer', $rId);
|
||||
}
|
||||
|
||||
// Add footnotes media files, relations, and contents
|
||||
|
|
@ -113,7 +114,7 @@ class Word2007 extends AbstractWriter implements WriterInterface
|
|||
}
|
||||
$objZip->addFromString('word/footnotes.xml', $this->getWriterPart('footnotes')->writeFootnotes(Footnote::getFootnoteElements()));
|
||||
$this->cTypes['override']["/word/footnotes.xml"] = 'footnotes';
|
||||
$this->docRels[] = array('target' => 'footnotes.xml', 'type' => 'footnotes', 'rID' => ++$rID);
|
||||
$this->docRels[] = array('target' => 'footnotes.xml', 'type' => 'footnotes', 'rID' => ++$rId);
|
||||
}
|
||||
|
||||
// Write dynamic files
|
||||
|
|
@ -207,12 +208,11 @@ class Word2007 extends AbstractWriter implements WriterInterface
|
|||
/**
|
||||
* Add header/footer content
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\Element\Section $section
|
||||
* @param mixed $objZip
|
||||
* @param string $elmType
|
||||
* @param integer $rID
|
||||
* @param integer $rId
|
||||
*/
|
||||
private function addHeaderFooterContent(&$section, $objZip, $elmType, &$rID)
|
||||
private function addHeaderFooterContent(Section &$section, $objZip, $elmType, &$rId)
|
||||
{
|
||||
$getFunction = $elmType == 'header' ? 'getHeaders' : 'getFooters';
|
||||
$writeFunction = $elmType == 'header' ? 'writeHeader' : 'writeFooter';
|
||||
|
|
@ -220,11 +220,11 @@ class Word2007 extends AbstractWriter implements WriterInterface
|
|||
$elmObjects = $section->$getFunction();
|
||||
foreach ($elmObjects as $index => &$elmObject) {
|
||||
$elmCount++;
|
||||
$elmObject->setRelationId(++$rID);
|
||||
$elmObject->setRelationId(++$rId);
|
||||
$elmFile = "{$elmType}{$elmCount}.xml";
|
||||
$objZip->addFromString("word/$elmFile", $this->getWriterPart($elmType)->$writeFunction($elmObject));
|
||||
$this->cTypes['override']["/word/$elmFile"] = $elmType;
|
||||
$this->docRels[] = array('target' => $elmFile, 'type' => $elmType, 'rID' => $rID);
|
||||
$this->docRels[] = array('target' => $elmFile, 'type' => $elmType, 'rID' => $rId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ class Base extends AbstractWriterPart
|
|||
*/
|
||||
protected function writeLink(XMLWriter $xmlWriter, Link $link, $withoutP = false)
|
||||
{
|
||||
$rID = $link->getRelationId() + ($link->isInSection() ? 6 : 0);
|
||||
$rId = $link->getRelationId() + ($link->isInSection() ? 6 : 0);
|
||||
$linkName = $link->getLinkName();
|
||||
if (is_null($linkName)) {
|
||||
$linkName = $link->getLinkSrc();
|
||||
|
|
@ -106,7 +106,7 @@ class Base extends AbstractWriterPart
|
|||
$this->writeInlineParagraphStyle($xmlWriter, $styleParagraph);
|
||||
}
|
||||
$xmlWriter->startElement('w:hyperlink');
|
||||
$xmlWriter->writeAttribute('r:id', 'rId' . $rID);
|
||||
$xmlWriter->writeAttribute('r:id', 'rId' . $rId);
|
||||
$xmlWriter->writeAttribute('w:history', '1');
|
||||
$xmlWriter->startElement('w:r');
|
||||
$this->writeInlineFontStyle($xmlWriter, $styleFont);
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(1, count(Footnote::getFootnoteElements()));
|
||||
$this->assertEquals(1, count(Footnote::getFootnoteLinkElements()));
|
||||
|
||||
Footnote::reset();
|
||||
Footnote::resetElements();
|
||||
$this->assertEquals(0, count(Footnote::getFootnoteElements()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ class MediaTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
$this->assertEquals(2, Media::countElements('footer1'));
|
||||
|
||||
Media::reset();
|
||||
Media::resetElements();
|
||||
$this->assertEquals(0, Media::countElements('footer1'));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class StyleTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
$this->assertNull(Style::getStyle('Unknown'));
|
||||
|
||||
Style::reset();
|
||||
Style::resetStyles();
|
||||
$this->assertEquals(0, count(Style::getStyles()));
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ class TOCTest extends \PHPUnit_Framework_TestCase
|
|||
$i++;
|
||||
}
|
||||
|
||||
TOC::reset();
|
||||
TOC::resetTitles();
|
||||
$this->assertEquals(0, count($toc->getTitles()));
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue