This commit is contained in:
Xes
2025-08-14 22:41:49 +02:00
parent 2de81ccc46
commit 8ce45119b6
39774 changed files with 4309466 additions and 0 deletions

View File

@@ -0,0 +1,95 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Collection;
/**
* Collection abstract class
*
* @since 0.10.0
*/
abstract class AbstractCollection
{
/**
* Items
*
* @var \PhpOffice\PhpWord\Element\AbstractContainer[]
*/
private $items = array();
/**
* Get items
*
* @return \PhpOffice\PhpWord\Element\AbstractContainer[]
*/
public function getItems()
{
return $this->items;
}
/**
* Get item by index
*
* @param int $index
* @return \PhpOffice\PhpWord\Element\AbstractContainer
*/
public function getItem($index)
{
if (array_key_exists($index, $this->items)) {
return $this->items[$index];
}
return null;
}
/**
* Set item.
*
* @param int $index
* @param \PhpOffice\PhpWord\Element\AbstractContainer $item
*/
public function setItem($index, $item)
{
if (array_key_exists($index, $this->items)) {
$this->items[$index] = $item;
}
}
/**
* Add new item
*
* @param \PhpOffice\PhpWord\Element\AbstractContainer $item
* @return int
*/
public function addItem($item)
{
$index = $this->countItems() + 1;
$this->items[$index] = $item;
return $index;
}
/**
* Get item count
*
* @return int
*/
public function countItems()
{
return count($this->items);
}
}

View File

@@ -0,0 +1,27 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Collection;
/**
* Bookmarks collection
*
* @since 0.12.0
*/
class Bookmarks extends AbstractCollection
{
}

View File

@@ -0,0 +1,27 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Collection;
/**
* Charts collection
*
* @since 0.12.0
*/
class Charts extends AbstractCollection
{
}

View File

@@ -0,0 +1,27 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Collection;
/**
* Comments collection
*
* @since 0.12.0
*/
class Comments extends AbstractCollection
{
}

View File

@@ -0,0 +1,27 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Collection;
/**
* Endnotes collection
*
* @since 0.10.0
*/
class Endnotes extends AbstractCollection
{
}

View File

@@ -0,0 +1,27 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Collection;
/**
* Footnotes collection
*
* @since 0.10.0
*/
class Footnotes extends AbstractCollection
{
}

View File

@@ -0,0 +1,27 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Collection;
/**
* Titles collection
*
* @since 0.10.0
*/
class Titles extends AbstractCollection
{
}

View File

@@ -0,0 +1,181 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\ComplexType;
use PhpOffice\PhpWord\SimpleType\NumberFormat;
/**
* Footnote properties
*
* @see http://www.datypic.com/sc/ooxml/e-w_footnotePr-1.html
*/
final class FootnoteProperties
{
const RESTART_NUMBER_CONTINUOUS = 'continuous';
const RESTART_NUMBER_EACH_SECTION = 'eachSect';
const RESTART_NUMBER_EACH_PAGE = 'eachPage';
const POSITION_PAGE_BOTTOM = 'pageBottom';
const POSITION_BENEATH_TEXT = 'beneathText';
const POSITION_SECTION_END = 'sectEnd';
const POSITION_DOC_END = 'docEnd';
/**
* Footnote Positioning Location
*
* @var string
*/
private $pos;
/**
* Footnote Numbering Format w:numFmt, one of PhpOffice\PhpWord\SimpleType\NumberFormat
*
* @var string
*/
private $numFmt;
/**
* Footnote and Endnote Numbering Starting Value
*
* @var float
*/
private $numStart;
/**
* Footnote and Endnote Numbering Restart Location
*
* @var string
*/
private $numRestart;
/**
* Get the Footnote Positioning Location
*
* @return string
*/
public function getPos()
{
return $this->pos;
}
/**
* Set the Footnote Positioning Location (pageBottom, beneathText, sectEnd, docEnd)
*
* @param string $pos
* @throws \InvalidArgumentException
* @return self
*/
public function setPos($pos)
{
$position = array(
self::POSITION_PAGE_BOTTOM,
self::POSITION_BENEATH_TEXT,
self::POSITION_SECTION_END,
self::POSITION_DOC_END,
);
if (in_array($pos, $position)) {
$this->pos = $pos;
} else {
throw new \InvalidArgumentException('Invalid value, on of ' . implode(', ', $position) . ' possible');
}
return $this;
}
/**
* Get the Footnote Numbering Format
*
* @return string
*/
public function getNumFmt()
{
return $this->numFmt;
}
/**
* Set the Footnote Numbering Format
*
* @param string $numFmt One of NumberFormat
* @return self
*/
public function setNumFmt($numFmt)
{
NumberFormat::validate($numFmt);
$this->numFmt = $numFmt;
return $this;
}
/**
* Get the Footnote Numbering Format
*
* @return float
*/
public function getNumStart()
{
return $this->numStart;
}
/**
* Set the Footnote Numbering Format
*
* @param float $numStart
* @return self
*/
public function setNumStart($numStart)
{
$this->numStart = $numStart;
return $this;
}
/**
* Get the Footnote and Endnote Numbering Starting Value
*
* @return string
*/
public function getNumRestart()
{
return $this->numRestart;
}
/**
* Set the Footnote and Endnote Numbering Starting Value (continuous, eachSect, eachPage)
*
* @param string $numRestart
* @throws \InvalidArgumentException
* @return self
*/
public function setNumRestart($numRestart)
{
$restartNumbers = array(
self::RESTART_NUMBER_CONTINUOUS,
self::RESTART_NUMBER_EACH_SECTION,
self::RESTART_NUMBER_EACH_PAGE,
);
if (in_array($numRestart, $restartNumbers)) {
$this->numRestart = $numRestart;
} else {
throw new \InvalidArgumentException('Invalid value, on of ' . implode(', ', $restartNumbers) . ' possible');
}
return $this;
}
}

View File

@@ -0,0 +1,106 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\ComplexType;
/**
* Spelling and Grammatical Checking State
*
* @see http://www.datypic.com/sc/ooxml/e-w_proofState-1.html
*/
final class ProofState
{
/**
* Check Completed
*/
const CLEAN = 'clean';
/**
* Check Not Completed
*/
const DIRTY = 'dirty';
/**
* Spell Checking State
*
* @var string
*/
private $spelling;
/**
* Grammatical Checking State
*
* @var string
*/
private $grammar;
/**
* Set the Spell Checking State (dirty or clean)
*
* @param string $spelling
* @throws \InvalidArgumentException
* @return self
*/
public function setSpelling($spelling)
{
if ($spelling == self::CLEAN || $spelling == self::DIRTY) {
$this->spelling = $spelling;
} else {
throw new \InvalidArgumentException('Invalid value, dirty or clean possible');
}
return $this;
}
/**
* Get the Spell Checking State
*
* @return string
*/
public function getSpelling()
{
return $this->spelling;
}
/**
* Set the Grammatical Checking State (dirty or clean)
*
* @param string $grammar
* @throws \InvalidArgumentException
* @return self
*/
public function setGrammar($grammar)
{
if ($grammar == self::CLEAN || $grammar == self::DIRTY) {
$this->grammar = $grammar;
} else {
throw new \InvalidArgumentException('Invalid value, dirty or clean possible');
}
return $this;
}
/**
* Get the Grammatical Checking State
*
* @return string
*/
public function getGrammar()
{
return $this->grammar;
}
}

View File

@@ -0,0 +1,59 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\ComplexType;
use PhpOffice\PhpWord\SimpleType\TblWidth as TblWidthSimpleType;
/**
* @see http://www.datypic.com/sc/ooxml/t-w_CT_TblWidth.html
*/
final class TblWidth
{
/** @var string */
private $type;
/** @var int */
private $value;
/**
* @param int $value If omitted, then its value shall be assumed to be 0
* @param string $type If omitted, then its value shall be assumed to be dxa
*/
public function __construct($value = 0, $type = TblWidthSimpleType::TWIP)
{
$this->value = $value;
TblWidthSimpleType::validate($type);
$this->type = $type;
}
/**
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* @return int
*/
public function getValue()
{
return $this->value;
}
}

View File

@@ -0,0 +1,166 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\ComplexType;
/**
* Visibility of Annotation Types
*
* @see http://www.datypic.com/sc/ooxml/e-w_revisionView-1.html
*/
final class TrackChangesView
{
/**
* Display Visual Indicator Of Markup Area
*
* @var bool
*/
private $markup;
/**
* Display Comments
*
* @var bool
*/
private $comments;
/**
* Display Content Revisions
*
* @var bool
*/
private $insDel;
/**
* Display Formatting Revisions
*
* @var bool
*/
private $formatting;
/**
* Display Ink Annotations
*
* @var bool
*/
private $inkAnnotations;
/**
* Get Display Visual Indicator Of Markup Area
*
* @return bool True if markup is shown
*/
public function hasMarkup()
{
return $this->markup;
}
/**
* Set Display Visual Indicator Of Markup Area
*
* @param bool $markup
* Set to true to show markup
*/
public function setMarkup($markup)
{
$this->markup = $markup === null ? true : $markup;
}
/**
* Get Display Comments
*
* @return bool True if comments are shown
*/
public function hasComments()
{
return $this->comments;
}
/**
* Set Display Comments
*
* @param bool $comments
* Set to true to show comments
*/
public function setComments($comments)
{
$this->comments = $comments === null ? true : $comments;
}
/**
* Get Display Content Revisions
*
* @return bool True if content revisions are shown
*/
public function hasInsDel()
{
return $this->insDel;
}
/**
* Set Display Content Revisions
*
* @param bool $insDel
* Set to true to show content revisions
*/
public function setInsDel($insDel)
{
$this->insDel = $insDel === null ? true : $insDel;
}
/**
* Get Display Formatting Revisions
*
* @return bool True if formatting revisions are shown
*/
public function hasFormatting()
{
return $this->formatting;
}
/**
* Set Display Formatting Revisions
*
* @param bool|null $formatting
* Set to true to show formatting revisions
*/
public function setFormatting($formatting = null)
{
$this->formatting = $formatting === null ? true : $formatting;
}
/**
* Get Display Ink Annotations
*
* @return bool True if ink annotations are shown
*/
public function hasInkAnnotations()
{
return $this->inkAnnotations;
}
/**
* Set Display Ink Annotations
*
* @param bool $inkAnnotations
* Set to true to show ink annotations
*/
public function setInkAnnotations($inkAnnotations)
{
$this->inkAnnotations = $inkAnnotations === null ? true : $inkAnnotations;
}
}

View File

@@ -0,0 +1,316 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
/**
* Container abstract class
*
* @method Text addText(string $text, mixed $fStyle = null, mixed $pStyle = null)
* @method TextRun addTextRun(mixed $pStyle = null)
* @method Bookmark addBookmark(string $name)
* @method Link addLink(string $target, string $text = null, mixed $fStyle = null, mixed $pStyle = null, boolean $internal = false)
* @method PreserveText addPreserveText(string $text, mixed $fStyle = null, mixed $pStyle = null)
* @method void addTextBreak(int $count = 1, mixed $fStyle = null, mixed $pStyle = null)
* @method ListItem addListItem(string $txt, int $depth = 0, mixed $font = null, mixed $list = null, mixed $para = null)
* @method ListItemRun addListItemRun(int $depth = 0, mixed $listStyle = null, mixed $pStyle = null)
* @method Footnote addFootnote(mixed $pStyle = null)
* @method Endnote addEndnote(mixed $pStyle = null)
* @method CheckBox addCheckBox(string $name, $text, mixed $fStyle = null, mixed $pStyle = null)
* @method Title addTitle(mixed $text, int $depth = 1)
* @method TOC addTOC(mixed $fontStyle = null, mixed $tocStyle = null, int $minDepth = 1, int $maxDepth = 9)
* @method PageBreak addPageBreak()
* @method Table addTable(mixed $style = null)
* @method Image addImage(string $source, mixed $style = null, bool $isWatermark = false, $name = null)
* @method OLEObject addOLEObject(string $source, mixed $style = null)
* @method TextBox addTextBox(mixed $style = null)
* @method Field addField(string $type = null, array $properties = array(), array $options = array(), mixed $text = null)
* @method Line addLine(mixed $lineStyle = null)
* @method Shape addShape(string $type, mixed $style = null)
* @method Chart addChart(string $type, array $categories, array $values, array $style = null, $seriesName = null)
* @method FormField addFormField(string $type, mixed $fStyle = null, mixed $pStyle = null)
* @method SDT addSDT(string $type)
*
* @method \PhpOffice\PhpWord\Element\OLEObject addObject(string $source, mixed $style = null) deprecated, use addOLEObject instead
*
* @since 0.10.0
*/
abstract class AbstractContainer extends AbstractElement
{
/**
* Elements collection
*
* @var \PhpOffice\PhpWord\Element\AbstractElement[]
*/
protected $elements = array();
/**
* Container type Section|Header|Footer|Footnote|Endnote|Cell|TextRun|TextBox|ListItemRun|TrackChange
*
* @var string
*/
protected $container;
/**
* Magic method to catch all 'addElement' variation
*
* This removes addText, addTextRun, etc. When adding new element, we have to
* add the model in the class docblock with `@method`.
*
* Warning: This makes capitalization matters, e.g. addCheckbox or addcheckbox won't work.
*
* @param mixed $function
* @param mixed $args
* @return \PhpOffice\PhpWord\Element\AbstractElement
*/
public function __call($function, $args)
{
$elements = array(
'Text', 'TextRun', 'Bookmark', 'Link', 'PreserveText', 'TextBreak',
'ListItem', 'ListItemRun', 'Table', 'Image', 'Object', 'OLEObject',
'Footnote', 'Endnote', 'CheckBox', 'TextBox', 'Field',
'Line', 'Shape', 'Title', 'TOC', 'PageBreak',
'Chart', 'FormField', 'SDT', 'Comment',
);
$functions = array();
foreach ($elements as $element) {
$functions['add' . strtolower($element)] = $element == 'Object' ? 'OLEObject' : $element;
}
// Run valid `add` command
$function = strtolower($function);
if (isset($functions[$function])) {
$element = $functions[$function];
// Special case for TextBreak
// @todo Remove the `$count` parameter in 1.0.0 to make this element similiar to other elements?
if ($element == 'TextBreak') {
list($count, $fontStyle, $paragraphStyle) = array_pad($args, 3, null);
if ($count === null) {
$count = 1;
}
for ($i = 1; $i <= $count; $i++) {
$this->addElement($element, $fontStyle, $paragraphStyle);
}
} else {
// All other elements
array_unshift($args, $element); // Prepend element name to the beginning of args array
return call_user_func_array(array($this, 'addElement'), $args);
}
}
return null;
}
/**
* Add element
*
* Each element has different number of parameters passed
*
* @param string $elementName
* @return \PhpOffice\PhpWord\Element\AbstractElement
*/
protected function addElement($elementName)
{
$elementClass = __NAMESPACE__ . '\\' . $elementName;
$this->checkValidity($elementName);
// Get arguments
$args = func_get_args();
$withoutP = in_array($this->container, array('TextRun', 'Footnote', 'Endnote', 'ListItemRun', 'Field'));
if ($withoutP && ($elementName == 'Text' || $elementName == 'PreserveText')) {
$args[3] = null; // Remove paragraph style for texts in textrun
}
// Create element using reflection
$reflection = new \ReflectionClass($elementClass);
$elementArgs = $args;
array_shift($elementArgs); // Shift the $elementName off the beginning of array
/** @var \PhpOffice\PhpWord\Element\AbstractElement $element Type hint */
$element = $reflection->newInstanceArgs($elementArgs);
// Set parent container
$element->setParentContainer($this);
$element->setElementIndex($this->countElements() + 1);
$element->setElementId();
$this->elements[] = $element;
return $element;
}
/**
* Get all elements
*
* @return \PhpOffice\PhpWord\Element\AbstractElement[]
*/
public function getElements()
{
return $this->elements;
}
/**
* Returns the element at the requested position
*
* @param int $index
* @return \PhpOffice\PhpWord\Element\AbstractElement|null
*/
public function getElement($index)
{
if (array_key_exists($index, $this->elements)) {
return $this->elements[$index];
}
return null;
}
/**
* Removes the element at requested index
*
* @param int|\PhpOffice\PhpWord\Element\AbstractElement $toRemove
*/
public function removeElement($toRemove)
{
if (is_int($toRemove) && array_key_exists($toRemove, $this->elements)) {
unset($this->elements[$toRemove]);
} elseif ($toRemove instanceof \PhpOffice\PhpWord\Element\AbstractElement) {
foreach ($this->elements as $key => $element) {
if ($element->getElementId() === $toRemove->getElementId()) {
unset($this->elements[$key]);
return;
}
}
}
}
/**
* Count elements
*
* @return int
*/
public function countElements()
{
return count($this->elements);
}
/**
* Check if a method is allowed for the current container
*
* @param string $method
*
* @throws \BadMethodCallException
* @return bool
*/
private function checkValidity($method)
{
$generalContainers = array(
'Section', 'Header', 'Footer', 'Footnote', 'Endnote', 'Cell', 'TextRun', 'TextBox', 'ListItemRun', 'TrackChange',
);
$validContainers = array(
'Text' => $generalContainers,
'Bookmark' => $generalContainers,
'Link' => $generalContainers,
'TextBreak' => $generalContainers,
'Image' => $generalContainers,
'OLEObject' => $generalContainers,
'Field' => $generalContainers,
'Line' => $generalContainers,
'Shape' => $generalContainers,
'FormField' => $generalContainers,
'SDT' => $generalContainers,
'TrackChange' => $generalContainers,
'TextRun' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox', 'TrackChange', 'ListItemRun'),
'ListItem' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'),
'ListItemRun' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'),
'Table' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'),
'CheckBox' => array('Section', 'Header', 'Footer', 'Cell', 'TextRun'),
'TextBox' => array('Section', 'Header', 'Footer', 'Cell'),
'Footnote' => array('Section', 'TextRun', 'Cell', 'ListItemRun'),
'Endnote' => array('Section', 'TextRun', 'Cell'),
'PreserveText' => array('Section', 'Header', 'Footer', 'Cell'),
'Title' => array('Section', 'Cell'),
'TOC' => array('Section'),
'PageBreak' => array('Section'),
'Chart' => array('Section', 'Cell'),
);
// Special condition, e.g. preservetext can only exists in cell when
// the cell is located in header or footer
$validSubcontainers = array(
'PreserveText' => array(array('Cell'), array('Header', 'Footer', 'Section')),
'Footnote' => array(array('Cell', 'TextRun'), array('Section')),
'Endnote' => array(array('Cell', 'TextRun'), array('Section')),
);
// Check if a method is valid for current container
if (isset($validContainers[$method])) {
if (!in_array($this->container, $validContainers[$method])) {
throw new \BadMethodCallException("Cannot add {$method} in {$this->container}.");
}
}
// Check if a method is valid for current container, located in other container
if (isset($validSubcontainers[$method])) {
$rules = $validSubcontainers[$method];
$containers = $rules[0];
$allowedDocParts = $rules[1];
foreach ($containers as $container) {
if ($this->container == $container && !in_array($this->getDocPart(), $allowedDocParts)) {
throw new \BadMethodCallException("Cannot add {$method} in {$this->container}.");
}
}
}
return true;
}
/**
* Create textrun element
*
* @deprecated 0.10.0
*
* @param mixed $paragraphStyle
*
* @return \PhpOffice\PhpWord\Element\TextRun
*
* @codeCoverageIgnore
*/
public function createTextRun($paragraphStyle = null)
{
return $this->addTextRun($paragraphStyle);
}
/**
* Create footnote element
*
* @deprecated 0.10.0
*
* @param mixed $paragraphStyle
*
* @return \PhpOffice\PhpWord\Element\Footnote
*
* @codeCoverageIgnore
*/
public function createFootnote($paragraphStyle = null)
{
return $this->addFootnote($paragraphStyle);
}
}

View File

@@ -0,0 +1,507 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\PhpWord;
/**
* Element abstract class
*
* @since 0.10.0
*/
abstract class AbstractElement
{
/**
* PhpWord object
*
* @var \PhpOffice\PhpWord\PhpWord
*/
protected $phpWord;
/**
* Section Id
*
* @var int
*/
protected $sectionId;
/**
* Document part type: Section|Header|Footer|Footnote|Endnote
*
* Used by textrun and cell container to determine where the element is
* located because it will affect the availability of other element,
* e.g. footnote will not be available when $docPart is header or footer.
*
* @var string
*/
protected $docPart = 'Section';
/**
* Document part Id
*
* For header and footer, this will be = ($sectionId - 1) * 3 + $index
* because the max number of header/footer in every page is 3, i.e.
* AUTO, FIRST, and EVEN (AUTO = ODD)
*
* @var int
*/
protected $docPartId = 1;
/**
* Index of element in the elements collection (start with 1)
*
* @var int
*/
protected $elementIndex = 1;
/**
* Unique Id for element
*
* @var string
*/
protected $elementId;
/**
* Relation Id
*
* @var int
*/
protected $relationId;
/**
* Depth of table container nested level; Primarily used for RTF writer/reader
*
* 0 = Not in a table; 1 = in a table; 2 = in a table inside another table, etc.
*
* @var int
*/
private $nestedLevel = 0;
/**
* A reference to the parent
*
* @var AbstractElement|null
*/
private $parent;
/**
* changed element info
*
* @var TrackChange
*/
private $trackChange;
/**
* Parent container type
*
* @var string
*/
private $parentContainer;
/**
* Has media relation flag; true for Link, Image, and Object
*
* @var bool
*/
protected $mediaRelation = false;
/**
* Is part of collection; true for Title, Footnote, Endnote, Chart, and Comment
*
* @var bool
*/
protected $collectionRelation = false;
/**
* The start position for the linked comment
*
* @var Comment
*/
protected $commentRangeStart;
/**
* The end position for the linked comment
*
* @var Comment
*/
protected $commentRangeEnd;
/**
* Get PhpWord
*
* @return \PhpOffice\PhpWord\PhpWord
*/
public function getPhpWord()
{
return $this->phpWord;
}
/**
* Set PhpWord as reference.
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
*/
public function setPhpWord(PhpWord $phpWord = null)
{
$this->phpWord = $phpWord;
}
/**
* Get section number
*
* @return int
*/
public function getSectionId()
{
return $this->sectionId;
}
/**
* Set doc part.
*
* @param string $docPart
* @param int $docPartId
*/
public function setDocPart($docPart, $docPartId = 1)
{
$this->docPart = $docPart;
$this->docPartId = $docPartId;
}
/**
* Get doc part
*
* @return string
*/
public function getDocPart()
{
return $this->docPart;
}
/**
* Get doc part Id
*
* @return int
*/
public function getDocPartId()
{
return $this->docPartId;
}
/**
* Return media element (image, object, link) container name
*
* @return string section|headerx|footerx|footnote|endnote
*/
private function getMediaPart()
{
$mediaPart = $this->docPart;
if ($mediaPart == 'Header' || $mediaPart == 'Footer') {
$mediaPart .= $this->docPartId;
}
return strtolower($mediaPart);
}
/**
* Get element index
*
* @return int
*/
public function getElementIndex()
{
return $this->elementIndex;
}
/**
* Set element index.
*
* @param int $value
*/
public function setElementIndex($value)
{
$this->elementIndex = $value;
}
/**
* Get element unique ID
*
* @return string
*/
public function getElementId()
{
return $this->elementId;
}
/**
* Set element unique ID from 6 first digit of md5.
*/
public function setElementId()
{
$this->elementId = substr(md5(rand()), 0, 6);
}
/**
* Get relation Id
*
* @return int
*/
public function getRelationId()
{
return $this->relationId;
}
/**
* Set relation Id.
*
* @param int $value
*/
public function setRelationId($value)
{
$this->relationId = $value;
}
/**
* Get nested level
*
* @return int
*/
public function getNestedLevel()
{
return $this->nestedLevel;
}
/**
* Get comment start
*
* @return Comment
*/
public function getCommentRangeStart()
{
return $this->commentRangeStart;
}
/**
* Set comment start
*
* @param Comment $value
*/
public function setCommentRangeStart(Comment $value)
{
if ($this instanceof Comment) {
throw new \InvalidArgumentException('Cannot set a Comment on a Comment');
}
$this->commentRangeStart = $value;
$this->commentRangeStart->setStartElement($this);
}
/**
* Get comment end
*
* @return Comment
*/
public function getCommentRangeEnd()
{
return $this->commentRangeEnd;
}
/**
* Set comment end
*
* @param Comment $value
*/
public function setCommentRangeEnd(Comment $value)
{
if ($this instanceof Comment) {
throw new \InvalidArgumentException('Cannot set a Comment on a Comment');
}
$this->commentRangeEnd = $value;
$this->commentRangeEnd->setEndElement($this);
}
/**
* Get parent element
*
* @return AbstractElement|null
*/
public function getParent()
{
return $this->parent;
}
/**
* Set parent container
*
* Passed parameter should be a container, except for Table (contain Row) and Row (contain Cell)
*
* @param \PhpOffice\PhpWord\Element\AbstractElement $container
*/
public function setParentContainer(self $container)
{
$this->parentContainer = substr(get_class($container), strrpos(get_class($container), '\\') + 1);
$this->parent = $container;
// Set nested level
$this->nestedLevel = $container->getNestedLevel();
if ($this->parentContainer == 'Cell') {
$this->nestedLevel++;
}
// Set phpword
$this->setPhpWord($container->getPhpWord());
// Set doc part
if (!$this instanceof Footnote) {
$this->setDocPart($container->getDocPart(), $container->getDocPartId());
}
$this->setMediaRelation();
$this->setCollectionRelation();
}
/**
* Set relation Id for media elements (link, image, object; legacy of OOXML)
*
* - Image element needs to be passed to Media object
* - Icon needs to be set for Object element
*/
private function setMediaRelation()
{
if (!$this instanceof Link && !$this instanceof Image && !$this instanceof OLEObject) {
return;
}
$elementName = substr(get_class($this), strrpos(get_class($this), '\\') + 1);
if ($elementName == 'OLEObject') {
$elementName = 'Object';
}
$mediaPart = $this->getMediaPart();
$source = $this->getSource();
$image = null;
if ($this instanceof Image) {
$image = $this;
}
$rId = Media::addElement($mediaPart, strtolower($elementName), $source, $image);
$this->setRelationId($rId);
if ($this instanceof OLEObject) {
$icon = $this->getIcon();
$rId = Media::addElement($mediaPart, 'image', $icon, new Image($icon));
$this->setImageRelationId($rId);
}
}
/**
* Set relation Id for elements that will be registered in the Collection subnamespaces.
*/
private function setCollectionRelation()
{
if ($this->collectionRelation === true && $this->phpWord instanceof PhpWord) {
$elementName = substr(get_class($this), strrpos(get_class($this), '\\') + 1);
$addMethod = "add{$elementName}";
$rId = $this->phpWord->$addMethod($this);
$this->setRelationId($rId);
}
}
/**
* Check if element is located in Section doc part (as opposed to Header/Footer)
*
* @return bool
*/
public function isInSection()
{
return $this->docPart == 'Section';
}
/**
* Set new style value
*
* @param mixed $styleObject Style object
* @param mixed $styleValue Style value
* @param bool $returnObject Always return object
* @return mixed
*/
protected function setNewStyle($styleObject, $styleValue = null, $returnObject = false)
{
if (!is_null($styleValue) && is_array($styleValue)) {
$styleObject->setStyleByArray($styleValue);
$style = $styleObject;
} else {
$style = $returnObject ? $styleObject : $styleValue;
}
return $style;
}
/**
* Sets the trackChange information
*
* @param TrackChange $trackChange
*/
public function setTrackChange(TrackChange $trackChange)
{
$this->trackChange = $trackChange;
}
/**
* Gets the trackChange information
*
* @return TrackChange
*/
public function getTrackChange()
{
return $this->trackChange;
}
/**
* Set changed
*
* @param string $type INSERTED|DELETED
* @param string $author
* @param null|int|\DateTime $date allways in UTC
*/
public function setChangeInfo($type, $author, $date = null)
{
$this->trackChange = new TrackChange($type, $author, $date);
}
/**
* Set enum value
*
* @param string|null $value
* @param string[] $enum
* @param string|null $default
*
* @throws \InvalidArgumentException
* @return string|null
*
* @todo Merge with the same method in AbstractStyle
*/
protected function setEnumVal($value = null, $enum = array(), $default = null)
{
if ($value !== null && trim($value) != '' && !empty($enum) && !in_array($value, $enum)) {
throw new \InvalidArgumentException("Invalid style value: {$value}");
} elseif ($value === null || trim($value) == '') {
$value = $default;
}
return $value;
}
}

View File

@@ -0,0 +1,60 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Shared\Text as SharedText;
/**
* Bookmark element
*/
class Bookmark extends AbstractElement
{
/**
* Bookmark Name
*
* @var string
*/
private $name;
/**
* Is part of collection
*
* @var bool
*/
protected $collectionRelation = true;
/**
* Create a new Bookmark Element
*
* @param string $name
*/
public function __construct($name = '')
{
$this->name = SharedText::toUTF8($name);
}
/**
* Get Bookmark name
*
* @return string
*/
public function getName()
{
return $this->name;
}
}

View File

@@ -0,0 +1,77 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\Cell as CellStyle;
/**
* Table cell element
*/
class Cell extends AbstractContainer
{
/**
* @var string Container type
*/
protected $container = 'Cell';
/**
* Cell width
*
* @var int
*/
private $width = null;
/**
* Cell style
*
* @var \PhpOffice\PhpWord\Style\Cell
*/
private $style;
/**
* Create new instance
*
* @param int $width
* @param array|\PhpOffice\PhpWord\Style\Cell $style
*/
public function __construct($width = null, $style = null)
{
$this->width = $width;
$this->style = $this->setNewStyle(new CellStyle(), $style, true);
}
/**
* Get cell style
*
* @return \PhpOffice\PhpWord\Style\Cell
*/
public function getStyle()
{
return $this->style;
}
/**
* Get cell width
*
* @return int
*/
public function getWidth()
{
return $this->width;
}
}

View File

@@ -0,0 +1,129 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\Chart as ChartStyle;
/**
* Chart element
*
* @since 0.12.0
*/
class Chart extends AbstractElement
{
/**
* Is part of collection
*
* @var bool
*/
protected $collectionRelation = true;
/**
* Type
*
* @var string
*/
private $type = 'pie';
/**
* Series
*
* @var array
*/
private $series = array();
/**
* Chart style
*
* @var \PhpOffice\PhpWord\Style\Chart
*/
private $style;
/**
* Create new instance
*
* @param string $type
* @param array $categories
* @param array $values
* @param array $style
* @param null|mixed $seriesName
*/
public function __construct($type, $categories, $values, $style = null, $seriesName = null)
{
$this->setType($type);
$this->addSeries($categories, $values, $seriesName);
$this->style = $this->setNewStyle(new ChartStyle(), $style, true);
}
/**
* Get type
*
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* Set type.
*
* @param string $value
*/
public function setType($value)
{
$enum = array('pie', 'doughnut', 'line', 'bar', 'stacked_bar', 'percent_stacked_bar', 'column', 'stacked_column', 'percent_stacked_column', 'area', 'radar', 'scatter');
$this->type = $this->setEnumVal($value, $enum, 'pie');
}
/**
* Add series
*
* @param array $categories
* @param array $values
* @param null|mixed $name
*/
public function addSeries($categories, $values, $name = null)
{
$this->series[] = array(
'categories' => $categories,
'values' => $values,
'name' => $name,
);
}
/**
* Get series
*
* @return array
*/
public function getSeries()
{
return $this->series;
}
/**
* Get chart style
*
* @return \PhpOffice\PhpWord\Style\Chart
*/
public function getStyle()
{
return $this->style;
}
}

View File

@@ -0,0 +1,72 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Shared\Text as SharedText;
/**
* Check box element
*
* @since 0.10.0
*/
class CheckBox extends Text
{
/**
* Name content
*
* @var string
*/
private $name;
/**
* Create new instance
*
* @param string $name
* @param string $text
* @param mixed $fontStyle
* @param mixed $paragraphStyle
*/
public function __construct($name = null, $text = null, $fontStyle = null, $paragraphStyle = null)
{
$this->setName($name);
parent::__construct($text, $fontStyle, $paragraphStyle);
}
/**
* Set name content
*
* @param string $name
* @return self
*/
public function setName($name)
{
$this->name = SharedText::toUTF8($name);
return $this;
}
/**
* Get name content
*
* @return string
*/
public function getName()
{
return $this->name;
}
}

View File

@@ -0,0 +1,122 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
/**
* Comment element
* @see http://datypic.com/sc/ooxml/t-w_CT_Comment.html
*/
class Comment extends TrackChange
{
/**
* Initials
*
* @var string
*/
private $initials;
/**
* The Element where this comment starts
*
* @var AbstractElement
*/
private $startElement;
/**
* The Element where this comment ends
*
* @var AbstractElement
*/
private $endElement;
/**
* Is part of collection
*
* @var bool
*/
protected $collectionRelation = true;
/**
* Create a new Comment Element
*
* @param string $author
* @param null|\DateTime $date
* @param string $initials
*/
public function __construct($author, $date = null, $initials = null)
{
parent::__construct(null, $author, $date);
$this->initials = $initials;
}
/**
* Get Initials
*
* @return string
*/
public function getInitials()
{
return $this->initials;
}
/**
* Sets the element where this comment starts
*
* @param \PhpOffice\PhpWord\Element\AbstractElement $value
*/
public function setStartElement(AbstractElement $value)
{
$this->startElement = $value;
if ($value->getCommentRangeStart() == null) {
$value->setCommentRangeStart($this);
}
}
/**
* Get the element where this comment starts
*
* @return \PhpOffice\PhpWord\Element\AbstractElement
*/
public function getStartElement()
{
return $this->startElement;
}
/**
* Sets the element where this comment ends
*
* @param \PhpOffice\PhpWord\Element\AbstractElement $value
*/
public function setEndElement(AbstractElement $value)
{
$this->endElement = $value;
if ($value->getCommentRangeEnd() == null) {
$value->setCommentRangeEnd($this);
}
}
/**
* Get the element where this comment ends
*
* @return \PhpOffice\PhpWord\Element\AbstractElement
*/
public function getEndElement()
{
return $this->endElement;
}
}

View File

@@ -0,0 +1,41 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
/**
* Endnote element
*
* @since 0.10.0
*/
class Endnote extends Footnote
{
/**
* @var string Container type
*/
protected $container = 'Endnote';
/**
* Create new instance
*
* @param string|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
*/
public function __construct($paragraphStyle = null)
{
parent::__construct($paragraphStyle);
}
}

View File

@@ -0,0 +1,299 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\Font;
/**
* Field element
*
* @since 0.11.0
* @see http://www.schemacentral.com/sc/ooxml/t-w_CT_SimpleField.html
*/
class Field extends AbstractElement
{
/**
* Field properties and options. Depending on type, a field can have different properties
* and options
*
* @var array
*/
protected $fieldsArray = array(
'PAGE' => array(
'properties' => array(
'format' => array('Arabic', 'ArabicDash', 'alphabetic', 'ALPHABETIC', 'roman', 'ROMAN'),
),
'options' => array('PreserveFormat'),
),
'NUMPAGES' => array(
'properties' => array(
'format' => array('Arabic', 'ArabicDash', 'CardText', 'DollarText', 'Ordinal', 'OrdText',
'alphabetic', 'ALPHABETIC', 'roman', 'ROMAN', 'Caps', 'FirstCap', 'Lower', 'Upper', ),
'numformat' => array('0', '0,00', '#.##0', '#.##0,00', '€ #.##0,00(€ #.##0,00)', '0%', '0,00%'),
),
'options' => array('PreserveFormat'),
),
'DATE' => array(
'properties' => array(
'dateformat' => array(
/* Generic formats */
'yyyy-MM-dd', 'yyyy-MM', 'MMM-yy', 'MMM-yyyy', 'h:mm am/pm', 'h:mm:ss am/pm', 'HH:mm', 'HH:mm:ss',
/* Day-Month-Year formats */
'dddd d MMMM yyyy', 'd MMMM yyyy', 'd-MMM-yy', 'd MMM. yy',
'd-M-yy', 'd-M-yy h:mm', 'd-M-yy h:mm:ss', 'd-M-yy h:mm am/pm', 'd-M-yy h:mm:ss am/pm', 'd-M-yy HH:mm', 'd-M-yy HH:mm:ss',
'd/M/yy', 'd/M/yy h:mm', 'd/M/yy h:mm:ss', 'd/M/yy h:mm am/pm', 'd/M/yy h:mm:ss am/pm', 'd/M/yy HH:mm', 'd/M/yy HH:mm:ss',
'd-M-yyyy', 'd-M-yyyy h:mm', 'd-M-yyyy h:mm:ss', 'd-M-yyyy h:mm am/pm', 'd-M-yyyy h:mm:ss am/pm', 'd-M-yyyy HH:mm', 'd-M-yyyy HH:mm:ss',
'd/M/yyyy', 'd/M/yyyy h:mm', 'd/M/yyyy h:mm:ss', 'd/M/yyyy h:mm am/pm', 'd/M/yyyy h:mm:ss am/pm', 'd/M/yyyy HH:mm', 'd/M/yyyy HH:mm:ss',
/* Month-Day-Year formats */
'dddd, MMMM d yyyy', 'MMMM d yyyy', 'MMM-d-yy', 'MMM. d yy',
'M-d-yy', 'M-d-yy h:mm', 'M-d-yy h:mm:ss', 'M-d-yy h:mm am/pm', 'M-d-yy h:mm:ss am/pm', 'M-d-yy HH:mm', 'M-d-yy HH:mm:ss',
'M/d/yy', 'M/d/yy h:mm', 'M/d/yy h:mm:ss', 'M/d/yy h:mm am/pm', 'M/d/yy h:mm:ss am/pm', 'M/d/yy HH:mm', 'M/d/yy HH:mm:ss',
'M-d-yyyy', 'M-d-yyyy h:mm', 'M-d-yyyy h:mm:ss', 'M-d-yyyy h:mm am/pm', 'M-d-yyyy h:mm:ss am/pm', 'M-d-yyyy HH:mm', 'M-d-yyyy HH:mm:ss',
'M/d/yyyy', 'M/d/yyyy h:mm', 'M/d/yyyy h:mm:ss', 'M/d/yyyy h:mm am/pm', 'M/d/yyyy h:mm:ss am/pm', 'M/d/yyyy HH:mm', 'M/d/yyyy HH:mm:ss',
),
),
'options' => array('PreserveFormat', 'LunarCalendar', 'SakaEraCalendar', 'LastUsedFormat'),
),
'MACROBUTTON' => array(
'properties' => array('macroname' => ''),
),
'XE' => array(
'properties' => array(),
'options' => array('Bold', 'Italic'),
),
'INDEX' => array(
'properties' => array(),
'options' => array('PreserveFormat'),
),
'STYLEREF' => array(
'properties' => array('StyleIdentifier' => ''),
'options' => array('PreserveFormat'),
),
);
/**
* Field type
*
* @var string
*/
protected $type;
/**
* Field text
*
* @var TextRun|string
*/
protected $text;
/**
* Field properties
*
* @var array
*/
protected $properties = array();
/**
* Field options
*
* @var array
*/
protected $options = array();
/**
* Font style
*
* @var string|\PhpOffice\PhpWord\Style\Font
*/
protected $fontStyle;
/**
* Set Font style
*
* @param string|array|\PhpOffice\PhpWord\Style\Font $style
* @return string|\PhpOffice\PhpWord\Style\Font
*/
public function setFontStyle($style = null)
{
if ($style instanceof Font) {
$this->fontStyle = $style;
} elseif (is_array($style)) {
$this->fontStyle = new Font('text');
$this->fontStyle->setStyleByArray($style);
} elseif (null === $style) {
$this->fontStyle = null;
} else {
$this->fontStyle = $style;
}
return $this->fontStyle;
}
/**
* Get Font style
*
* @return string|\PhpOffice\PhpWord\Style\Font
*/
public function getFontStyle()
{
return $this->fontStyle;
}
/**
* Create a new Field Element
*
* @param string $type
* @param array $properties
* @param array $options
* @param TextRun|string|null $text
* @param string|array|\PhpOffice\PhpWord\Style\Font $fontStyle
*/
public function __construct($type = null, $properties = array(), $options = array(), $text = null, $fontStyle = null)
{
$this->setType($type);
$this->setProperties($properties);
$this->setOptions($options);
$this->setText($text);
$this->setFontStyle($fontStyle);
}
/**
* Set Field type
*
* @param string $type
*
* @throws \InvalidArgumentException
* @return string
*/
public function setType($type = null)
{
if (isset($type)) {
if (isset($this->fieldsArray[$type])) {
$this->type = $type;
} else {
throw new \InvalidArgumentException("Invalid type '$type'");
}
}
return $this->type;
}
/**
* Get Field type
*
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* Set Field properties
*
* @param array $properties
*
* @throws \InvalidArgumentException
* @return self
*/
public function setProperties($properties = array())
{
if (is_array($properties)) {
foreach (array_keys($properties) as $propkey) {
if (!(isset($this->fieldsArray[$this->type]['properties'][$propkey]))) {
throw new \InvalidArgumentException("Invalid property '$propkey'");
}
}
$this->properties = array_merge($this->properties, $properties);
}
return $this->properties;
}
/**
* Get Field properties
*
* @return array
*/
public function getProperties()
{
return $this->properties;
}
/**
* Set Field options
*
* @param array $options
*
* @throws \InvalidArgumentException
* @return self
*/
public function setOptions($options = array())
{
if (is_array($options)) {
foreach (array_keys($options) as $optionkey) {
if (!(isset($this->fieldsArray[$this->type]['options'][$optionkey])) && substr($optionkey, 0, 1) !== '\\') {
throw new \InvalidArgumentException("Invalid option '$optionkey', possible values are " . implode(', ', $this->fieldsArray[$this->type]['options']));
}
}
$this->options = array_merge($this->options, $options);
}
return $this->options;
}
/**
* Get Field properties
*
* @return array
*/
public function getOptions()
{
return $this->options;
}
/**
* Set Field text
*
* @param string|TextRun $text
*
* @throws \InvalidArgumentException
* @return null|string|TextRun
*/
public function setText($text = null)
{
if (isset($text)) {
if (is_string($text) || $text instanceof TextRun) {
$this->text = $text;
} else {
throw new \InvalidArgumentException('Invalid text');
}
}
return $this->text;
}
/**
* Get Field text
*
* @return string|TextRun
*/
public function getText()
{
return $this->text;
}
}

View File

@@ -0,0 +1,116 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
/**
* Footer element
*/
class Footer extends AbstractContainer
{
/**
* Header/footer types constants
*
* @var string
* @see http://www.datypic.com/sc/ooxml/t-w_ST_HdrFtr.html Header or Footer Type
*/
const AUTO = 'default'; // default and odd pages
const FIRST = 'first';
const EVEN = 'even';
/**
* @var string Container type
*/
protected $container = 'Footer';
/**
* Header type
*
* @var string
*/
protected $type = self::AUTO;
/**
* Create new instance
*
* @param int $sectionId
* @param int $containerId
* @param string $type
*/
public function __construct($sectionId, $containerId = 1, $type = self::AUTO)
{
$this->sectionId = $sectionId;
$this->setType($type);
$this->setDocPart($this->container, ($sectionId - 1) * 3 + $containerId);
}
/**
* Set type.
*
* @since 0.10.0
*
* @param string $value
*/
public function setType($value = self::AUTO)
{
if (!in_array($value, array(self::AUTO, self::FIRST, self::EVEN))) {
$value = self::AUTO;
}
$this->type = $value;
}
/**
* Get type
*
* @return string
* @since 0.10.0
*/
public function getType()
{
return $this->type;
}
/**
* Reset type to default
*
* @return string
*/
public function resetType()
{
return $this->type = self::AUTO;
}
/**
* First page only header
*
* @return string
*/
public function firstPage()
{
return $this->type = self::FIRST;
}
/**
* Even numbered pages only
*
* @return string
*/
public function evenPage()
{
return $this->type = self::EVEN;
}
}

View File

@@ -0,0 +1,89 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\Paragraph;
class Footnote extends AbstractContainer
{
/**
* @var string Container type
*/
protected $container = 'Footnote';
/**
* Paragraph style
*
* @var string|\PhpOffice\PhpWord\Style\Paragraph
*/
protected $paragraphStyle;
/**
* Is part of collection
*
* @var bool
*/
protected $collectionRelation = true;
/**
* Create new instance
*
* @param string|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
*/
public function __construct($paragraphStyle = null)
{
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
$this->setDocPart($this->container);
}
/**
* Get paragraph style
*
* @return string|\PhpOffice\PhpWord\Style\Paragraph
*/
public function getParagraphStyle()
{
return $this->paragraphStyle;
}
/**
* Get Footnote Reference ID
*
* @deprecated 0.10.0
* @codeCoverageIgnore
*
* @return int
*/
public function getReferenceId()
{
return $this->getRelationId();
}
/**
* Set Footnote Reference ID
*
* @deprecated 0.10.0
* @codeCoverageIgnore
*
* @param int $rId
*/
public function setReferenceId($rId)
{
$this->setRelationId($rId);
}
}

View File

@@ -0,0 +1,195 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
/**
* Form field element
*
* @since 0.12.0
* @see http://www.datypic.com/sc/ooxml/t-w_CT_FFData.html
*/
class FormField extends Text
{
/**
* Form field type: textinput|checkbox|dropdown
*
* @var string
*/
private $type = 'textinput';
/**
* Form field name
*
* @var string|bool|int
*/
private $name;
/**
* Default value
*
* - TextInput: string
* - CheckBox: bool
* - DropDown: int Index of entries (zero based)
*
* @var string|bool|int
*/
private $default;
/**
* Value
*
* @var string|bool|int
*/
private $value;
/**
* Dropdown entries
*
* @var array
*/
private $entries = array();
/**
* Create new instance
*
* @param string $type
* @param mixed $fontStyle
* @param mixed $paragraphStyle
*/
public function __construct($type, $fontStyle = null, $paragraphStyle = null)
{
parent::__construct(null, $fontStyle, $paragraphStyle);
$this->setType($type);
}
/**
* Get type
*
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* Set type
*
* @param string $value
* @return self
*/
public function setType($value)
{
$enum = array('textinput', 'checkbox', 'dropdown');
$this->type = $this->setEnumVal($value, $enum, $this->type);
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set name
*
* @param string|bool|int $value
* @return self
*/
public function setName($value)
{
$this->name = $value;
return $this;
}
/**
* Get default
*
* @return string|bool|int
*/
public function getDefault()
{
return $this->default;
}
/**
* Set default
*
* @param string|bool|int $value
* @return self
*/
public function setDefault($value)
{
$this->default = $value;
return $this;
}
/**
* Get value
*
* @return string|bool|int
*/
public function getValue()
{
return $this->value;
}
/**
* Set value
*
* @param string|bool|int $value
* @return self
*/
public function setValue($value)
{
$this->value = $value;
return $this;
}
/**
* Get entries
*
* @return array
*/
public function getEntries()
{
return $this->entries;
}
/**
* Set entries
*
* @param array $value
* @return self
*/
public function setEntries($value)
{
$this->entries = $value;
return $this;
}
}

View File

@@ -0,0 +1,41 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
/**
* Header element
*/
class Header extends Footer
{
/**
* @var string Container type
*/
protected $container = 'Header';
/**
* Add a Watermark Element
*
* @param string $src
* @param mixed $style
* @return Image
*/
public function addWatermark($src, $style = null)
{
return $this->addImage($src, $style, true);
}
}

View File

@@ -0,0 +1,602 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Exception\CreateTemporaryFileException;
use PhpOffice\PhpWord\Exception\InvalidImageException;
use PhpOffice\PhpWord\Exception\UnsupportedImageTypeException;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Shared\ZipArchive;
use PhpOffice\PhpWord\Style\Image as ImageStyle;
/**
* Image element
*/
class Image extends AbstractElement
{
/**
* Image source type constants
*/
const SOURCE_LOCAL = 'local'; // Local images
const SOURCE_GD = 'gd'; // Generated using GD
const SOURCE_ARCHIVE = 'archive'; // Image in archives zip://$archive#$image
const SOURCE_STRING = 'string'; // Image from string
/**
* Image source
*
* @var string
*/
private $source;
/**
* Source type: local|gd|archive
*
* @var string
*/
private $sourceType;
/**
* Image style
*
* @var ImageStyle
*/
private $style;
/**
* Is watermark
*
* @var bool
*/
private $watermark;
/**
* Name of image
*
* @var string
*/
private $name;
/**
* Image type
*
* @var string
*/
private $imageType;
/**
* Image create function
*
* @var string
*/
private $imageCreateFunc;
/**
* Image function
*
* @var string
*/
private $imageFunc;
/**
* Image extension
*
* @var string
*/
private $imageExtension;
/**
* Is memory image
*
* @var bool
*/
private $memoryImage;
/**
* Image target file name
*
* @var string
*/
private $target;
/**
* Image media index
*
* @var int
*/
private $mediaIndex;
/**
* Has media relation flag; true for Link, Image, and Object
*
* @var bool
*/
protected $mediaRelation = true;
/**
* Create new image element
*
* @param string $source
* @param mixed $style
* @param bool $watermark
* @param string $name
*
* @throws \PhpOffice\PhpWord\Exception\InvalidImageException
* @throws \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException
*/
public function __construct($source, $style = null, $watermark = false, $name = null)
{
$this->source = $source;
$this->style = $this->setNewStyle(new ImageStyle(), $style, true);
$this->setIsWatermark($watermark);
$this->setName($name);
$this->checkImage();
}
/**
* Get Image style
*
* @return ImageStyle
*/
public function getStyle()
{
return $this->style;
}
/**
* Get image source
*
* @return string
*/
public function getSource()
{
return $this->source;
}
/**
* Get image source type
*
* @return string
*/
public function getSourceType()
{
return $this->sourceType;
}
/**
* Sets the image name
*
* @param string $value
*/
public function setName($value)
{
$this->name = $value;
}
/**
* Get image name
*
* @return null|string
*/
public function getName()
{
return $this->name;
}
/**
* Get image media ID
*
* @return string
*/
public function getMediaId()
{
return md5($this->source);
}
/**
* Get is watermark
*
* @return bool
*/
public function isWatermark()
{
return $this->watermark;
}
/**
* Set is watermark
*
* @param bool $value
*/
public function setIsWatermark($value)
{
$this->watermark = $value;
}
/**
* Get image type
*
* @return string
*/
public function getImageType()
{
return $this->imageType;
}
/**
* Get image create function
*
* @return string
*/
public function getImageCreateFunction()
{
return $this->imageCreateFunc;
}
/**
* Get image function
*
* @return string
*/
public function getImageFunction()
{
return $this->imageFunc;
}
/**
* Get image extension
*
* @return string
*/
public function getImageExtension()
{
return $this->imageExtension;
}
/**
* Get is memory image
*
* @return bool
*/
public function isMemImage()
{
return $this->memoryImage;
}
/**
* Get target file name
*
* @return string
*/
public function getTarget()
{
return $this->target;
}
/**
* Set target file name.
*
* @param string $value
*/
public function setTarget($value)
{
$this->target = $value;
}
/**
* Get media index
*
* @return int
*/
public function getMediaIndex()
{
return $this->mediaIndex;
}
/**
* Set media index.
*
* @param int $value
*/
public function setMediaIndex($value)
{
$this->mediaIndex = $value;
}
/**
* Get image string data
*
* @param bool $base64
* @return string|null
* @since 0.11.0
*/
public function getImageStringData($base64 = false)
{
$source = $this->source;
$actualSource = null;
$imageBinary = null;
$imageData = null;
$isTemp = false;
// Get actual source from archive image or other source
// Return null if not found
if ($this->sourceType == self::SOURCE_ARCHIVE) {
$source = substr($source, 6);
list($zipFilename, $imageFilename) = explode('#', $source);
$zip = new ZipArchive();
if ($zip->open($zipFilename) !== false) {
if ($zip->locateName($imageFilename) !== false) {
$isTemp = true;
$zip->extractTo(Settings::getTempDir(), $imageFilename);
$actualSource = Settings::getTempDir() . DIRECTORY_SEPARATOR . $imageFilename;
}
}
$zip->close();
} else {
$actualSource = $source;
}
// Can't find any case where $actualSource = null hasn't captured by
// preceding exceptions. Please uncomment when you find the case and
// put the case into Element\ImageTest.
// if ($actualSource === null) {
// return null;
// }
// Read image binary data and convert to hex/base64 string
if ($this->sourceType == self::SOURCE_GD) {
$imageResource = call_user_func($this->imageCreateFunc, $actualSource);
if ($this->imageType === 'image/png') {
// PNG images need to preserve alpha channel information
imagesavealpha($imageResource, true);
}
ob_start();
call_user_func($this->imageFunc, $imageResource);
$imageBinary = ob_get_contents();
ob_end_clean();
} elseif ($this->sourceType == self::SOURCE_STRING) {
$imageBinary = $this->source;
} else {
$fileHandle = fopen($actualSource, 'rb', false);
if ($fileHandle !== false) {
$imageBinary = fread($fileHandle, filesize($actualSource));
fclose($fileHandle);
}
}
if ($imageBinary !== null) {
if ($base64) {
$imageData = chunk_split(base64_encode($imageBinary));
} else {
$imageData = chunk_split(bin2hex($imageBinary));
}
}
// Delete temporary file if necessary
if ($isTemp === true) {
@unlink($actualSource);
}
return $imageData;
}
/**
* Check memory image, supported type, image functions, and proportional width/height.
*
* @throws \PhpOffice\PhpWord\Exception\InvalidImageException
* @throws \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException
*/
private function checkImage()
{
$this->setSourceType();
// Check image data
if ($this->sourceType == self::SOURCE_ARCHIVE) {
$imageData = $this->getArchiveImageSize($this->source);
} elseif ($this->sourceType == self::SOURCE_STRING) {
$imageData = $this->getStringImageSize($this->source);
} else {
$imageData = @getimagesize($this->source);
}
if (!is_array($imageData)) {
throw new InvalidImageException(sprintf('Invalid image: %s', $this->source));
}
list($actualWidth, $actualHeight, $imageType) = $imageData;
// Check image type support
$supportedTypes = array(IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_PNG);
if ($this->sourceType != self::SOURCE_GD && $this->sourceType != self::SOURCE_STRING) {
$supportedTypes = array_merge($supportedTypes, array(IMAGETYPE_BMP, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM));
}
if (!in_array($imageType, $supportedTypes)) {
throw new UnsupportedImageTypeException();
}
// Define image functions
$this->imageType = image_type_to_mime_type($imageType);
$this->setFunctions();
$this->setProportionalSize($actualWidth, $actualHeight);
}
/**
* Set source type.
*/
private function setSourceType()
{
if (stripos(strrev($this->source), strrev('.php')) === 0) {
$this->memoryImage = true;
$this->sourceType = self::SOURCE_GD;
} elseif (strpos($this->source, 'zip://') !== false) {
$this->memoryImage = false;
$this->sourceType = self::SOURCE_ARCHIVE;
} elseif (filter_var($this->source, FILTER_VALIDATE_URL) !== false) {
$this->memoryImage = true;
if (strpos($this->source, 'https') === 0) {
$fileContent = file_get_contents($this->source);
$this->source = $fileContent;
$this->sourceType = self::SOURCE_STRING;
} else {
$this->sourceType = self::SOURCE_GD;
}
} elseif ((strpos($this->source, chr(0)) === false) && @file_exists($this->source)) {
$this->memoryImage = false;
$this->sourceType = self::SOURCE_LOCAL;
} else {
$this->memoryImage = true;
$this->sourceType = self::SOURCE_STRING;
}
}
/**
* Get image size from archive
*
* @since 0.12.0 Throws CreateTemporaryFileException.
*
* @param string $source
*
* @throws \PhpOffice\PhpWord\Exception\CreateTemporaryFileException
*
* @return array|null
*/
private function getArchiveImageSize($source)
{
$imageData = null;
$source = substr($source, 6);
list($zipFilename, $imageFilename) = explode('#', $source);
$tempFilename = tempnam(Settings::getTempDir(), 'PHPWordImage');
if (false === $tempFilename) {
throw new CreateTemporaryFileException(); // @codeCoverageIgnore
}
$zip = new ZipArchive();
if ($zip->open($zipFilename) !== false) {
if ($zip->locateName($imageFilename) !== false) {
$imageContent = $zip->getFromName($imageFilename);
if ($imageContent !== false) {
file_put_contents($tempFilename, $imageContent);
$imageData = getimagesize($tempFilename);
unlink($tempFilename);
}
}
$zip->close();
}
return $imageData;
}
/**
* get image size from string
*
* @param string $source
*
* @codeCoverageIgnore this method is just a replacement for getimagesizefromstring which exists only as of PHP 5.4
*/
private function getStringImageSize($source)
{
$result = false;
if (!function_exists('getimagesizefromstring')) {
$uri = 'data://application/octet-stream;base64,' . base64_encode($source);
$result = @getimagesize($uri);
} else {
$result = @getimagesizefromstring($source);
}
return $result;
}
/**
* Set image functions and extensions.
*/
private function setFunctions()
{
switch ($this->imageType) {
case 'image/png':
$this->imageCreateFunc = $this->sourceType == self::SOURCE_STRING ? 'imagecreatefromstring' : 'imagecreatefrompng';
$this->imageFunc = 'imagepng';
$this->imageExtension = 'png';
break;
case 'image/gif':
$this->imageCreateFunc = $this->sourceType == self::SOURCE_STRING ? 'imagecreatefromstring' : 'imagecreatefromgif';
$this->imageFunc = 'imagegif';
$this->imageExtension = 'gif';
break;
case 'image/jpeg':
case 'image/jpg':
$this->imageCreateFunc = $this->sourceType == self::SOURCE_STRING ? 'imagecreatefromstring' : 'imagecreatefromjpeg';
$this->imageFunc = 'imagejpeg';
$this->imageExtension = 'jpg';
break;
case 'image/bmp':
case 'image/x-ms-bmp':
$this->imageType = 'image/bmp';
$this->imageExtension = 'bmp';
break;
case 'image/tiff':
$this->imageExtension = 'tif';
break;
}
}
/**
* Set proportional width/height if one dimension not available.
*
* @param int $actualWidth
* @param int $actualHeight
*/
private function setProportionalSize($actualWidth, $actualHeight)
{
$styleWidth = $this->style->getWidth();
$styleHeight = $this->style->getHeight();
if (!($styleWidth && $styleHeight)) {
if ($styleWidth == null && $styleHeight == null) {
$this->style->setWidth($actualWidth);
$this->style->setHeight($actualHeight);
} elseif ($styleWidth) {
$this->style->setHeight($actualHeight * ($styleWidth / $actualWidth));
} else {
$this->style->setWidth($actualWidth * ($styleHeight / $actualHeight));
}
}
}
/**
* Get is watermark
*
* @deprecated 0.10.0
*
* @codeCoverageIgnore
*/
public function getIsWatermark()
{
return $this->isWatermark();
}
/**
* Get is memory image
*
* @deprecated 0.10.0
*
* @codeCoverageIgnore
*/
public function getIsMemImage()
{
return $this->isMemImage();
}
}

View File

@@ -0,0 +1,53 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\Line as LineStyle;
/**
* Line element
*/
class Line extends AbstractElement
{
/**
* Line style
*
* @var \PhpOffice\PhpWord\Style\Line
*/
private $style;
/**
* Create new line element
*
* @param mixed $style
*/
public function __construct($style = null)
{
$this->style = $this->setNewStyle(new LineStyle(), $style);
}
/**
* Get line style
*
* @return \PhpOffice\PhpWord\Style\Line
*/
public function getStyle()
{
return $this->style;
}
}

View File

@@ -0,0 +1,180 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Shared\Text as SharedText;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
/**
* Link element
*/
class Link extends AbstractElement
{
/**
* Link source
*
* @var string
*/
private $source;
/**
* Link text
*
* @var string
*/
private $text;
/**
* Font style
*
* @var string|\PhpOffice\PhpWord\Style\Font
*/
private $fontStyle;
/**
* Paragraph style
*
* @var string|\PhpOffice\PhpWord\Style\Paragraph
*/
private $paragraphStyle;
/**
* Has media relation flag; true for Link, Image, and Object
*
* @var bool
*/
protected $mediaRelation = true;
/**
* Has internal flag - anchor to internal bookmark
*
* @var bool
*/
protected $internal = false;
/**
* Create a new Link Element
*
* @param string $source
* @param string $text
* @param mixed $fontStyle
* @param mixed $paragraphStyle
* @param bool $internal
*/
public function __construct($source, $text = null, $fontStyle = null, $paragraphStyle = null, $internal = false)
{
$this->source = SharedText::toUTF8($source);
$this->text = is_null($text) ? $this->source : SharedText::toUTF8($text);
$this->fontStyle = $this->setNewStyle(new Font('text'), $fontStyle);
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
$this->internal = $internal;
}
/**
* Get link source
*
* @return string
*/
public function getSource()
{
return $this->source;
}
/**
* Get link text
*
* @return string
*/
public function getText()
{
return $this->text;
}
/**
* Get Text style
*
* @return string|\PhpOffice\PhpWord\Style\Font
*/
public function getFontStyle()
{
return $this->fontStyle;
}
/**
* Get Paragraph style
*
* @return string|\PhpOffice\PhpWord\Style\Paragraph
*/
public function getParagraphStyle()
{
return $this->paragraphStyle;
}
/**
* Get link target
*
* @deprecated 0.12.0
*
* @return string
*
* @codeCoverageIgnore
*/
public function getTarget()
{
return $this->source;
}
/**
* Get Link source
*
* @deprecated 0.10.0
*
* @return string
*
* @codeCoverageIgnore
*/
public function getLinkSrc()
{
return $this->getSource();
}
/**
* Get Link name
*
* @deprecated 0.10.0
*
* @return string
*
* @codeCoverageIgnore
*/
public function getLinkName()
{
return $this->getText();
}
/**
* is internal
*
* @return bool
*/
public function isInternal()
{
return $this->internal;
}
}

View File

@@ -0,0 +1,111 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Shared\Text as SharedText;
use PhpOffice\PhpWord\Style\ListItem as ListItemStyle;
/**
* List item element
*/
class ListItem extends AbstractElement
{
/**
* Element style
*
* @var \PhpOffice\PhpWord\Style\ListItem
*/
private $style;
/**
* Text object
*
* @var \PhpOffice\PhpWord\Element\Text
*/
private $textObject;
/**
* Depth
*
* @var int
*/
private $depth;
/**
* Create a new ListItem
*
* @param string $text
* @param int $depth
* @param mixed $fontStyle
* @param array|string|null $listStyle
* @param mixed $paragraphStyle
*/
public function __construct($text, $depth = 0, $fontStyle = null, $listStyle = null, $paragraphStyle = null)
{
$this->textObject = new Text(SharedText::toUTF8($text), $fontStyle, $paragraphStyle);
$this->depth = $depth;
// Version >= 0.10.0 will pass numbering style name. Older version will use old method
if (!is_null($listStyle) && is_string($listStyle)) {
$this->style = new ListItemStyle($listStyle); // @codeCoverageIgnore
} else {
$this->style = $this->setNewStyle(new ListItemStyle(), $listStyle, true);
}
}
/**
* Get style
*
* @return \PhpOffice\PhpWord\Style\ListItem
*/
public function getStyle()
{
return $this->style;
}
/**
* Get Text object
*
* @return \PhpOffice\PhpWord\Element\Text
*/
public function getTextObject()
{
return $this->textObject;
}
/**
* Get depth
*
* @return int
*/
public function getDepth()
{
return $this->depth;
}
/**
* Get text
*
* @return string
* @since 0.11.0
*/
public function getText()
{
return $this->textObject->getText();
}
}

View File

@@ -0,0 +1,85 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\ListItem as ListItemStyle;
/**
* List item element
*/
class ListItemRun extends TextRun
{
/**
* @var string Container type
*/
protected $container = 'ListItemRun';
/**
* ListItem Style
*
* @var \PhpOffice\PhpWord\Style\ListItem
*/
private $style;
/**
* ListItem Depth
*
* @var int
*/
private $depth;
/**
* Create a new ListItem
*
* @param int $depth
* @param array|string|null $listStyle
* @param mixed $paragraphStyle
*/
public function __construct($depth = 0, $listStyle = null, $paragraphStyle = null)
{
$this->depth = $depth;
// Version >= 0.10.0 will pass numbering style name. Older version will use old method
if (!is_null($listStyle) && is_string($listStyle)) {
$this->style = new ListItemStyle($listStyle);
} else {
$this->style = $this->setNewStyle(new ListItemStyle(), $listStyle, true);
}
parent::__construct($paragraphStyle);
}
/**
* Get ListItem style.
*
* @return \PhpOffice\PhpWord\Style\ListItem
*/
public function getStyle()
{
return $this->style;
}
/**
* Get ListItem depth.
*
* @return int
*/
public function getDepth()
{
return $this->depth;
}
}

View File

@@ -0,0 +1,169 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Exception\InvalidObjectException;
use PhpOffice\PhpWord\Style\Image as ImageStyle;
/**
* OLEObject element
*/
class OLEObject extends AbstractElement
{
/**
* Ole-Object Src
*
* @var string
*/
private $source;
/**
* Image Style
*
* @var \PhpOffice\PhpWord\Style\Image
*/
private $style;
/**
* Icon
*
* @var string
*/
private $icon;
/**
* Image Relation ID
*
* @var int
*/
private $imageRelationId;
/**
* Has media relation flag; true for Link, Image, and Object
*
* @var bool
*/
protected $mediaRelation = true;
/**
* Create a new Ole-Object Element
*
* @param string $source
* @param mixed $style
*
* @throws \PhpOffice\PhpWord\Exception\InvalidObjectException
*/
public function __construct($source, $style = null)
{
$supportedTypes = array('xls', 'doc', 'ppt', 'xlsx', 'docx', 'pptx');
$pathInfo = pathinfo($source);
if (file_exists($source) && in_array($pathInfo['extension'], $supportedTypes)) {
$ext = $pathInfo['extension'];
if (strlen($ext) == 4 && strtolower(substr($ext, -1)) == 'x') {
$ext = substr($ext, 0, -1);
}
$this->source = $source;
$this->style = $this->setNewStyle(new ImageStyle(), $style, true);
$this->icon = realpath(__DIR__ . "/../resources/{$ext}.png");
return;
}
throw new InvalidObjectException();
}
/**
* Get object source
*
* @return string
*/
public function getSource()
{
return $this->source;
}
/**
* Get object style
*
* @return \PhpOffice\PhpWord\Style\Image
*/
public function getStyle()
{
return $this->style;
}
/**
* Get object icon
*
* @return string
*/
public function getIcon()
{
return $this->icon;
}
/**
* Get image relation ID
*
* @return int
*/
public function getImageRelationId()
{
return $this->imageRelationId;
}
/**
* Set Image Relation ID.
*
* @param int $rId
*/
public function setImageRelationId($rId)
{
$this->imageRelationId = $rId;
}
/**
* Get Object ID
*
* @deprecated 0.10.0
*
* @return int
*
* @codeCoverageIgnore
*/
public function getObjectId()
{
return $this->relationId + 1325353440;
}
/**
* Set Object ID
*
* @deprecated 0.10.0
*
* @param int $objId
*
* @codeCoverageIgnore
*/
public function setObjectId($objId)
{
$this->relationId = $objId;
}
}

View File

@@ -0,0 +1,31 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
/**
* Page break element
*/
class PageBreak extends AbstractElement
{
/**
* Create new page break
*/
public function __construct()
{
}
}

View File

@@ -0,0 +1,98 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Shared\Text as SharedText;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
/**
* Preserve text/field element
*/
class PreserveText extends AbstractElement
{
/**
* Text content
*
* @var string|array
*/
private $text;
/**
* Text style
*
* @var string|\PhpOffice\PhpWord\Style\Font
*/
private $fontStyle;
/**
* Paragraph style
*
* @var string|\PhpOffice\PhpWord\Style\Paragraph
*/
private $paragraphStyle;
/**
* Create a new Preserve Text Element
*
* @param string $text
* @param mixed $fontStyle
* @param mixed $paragraphStyle
*/
public function __construct($text = null, $fontStyle = null, $paragraphStyle = null)
{
$this->fontStyle = $this->setNewStyle(new Font('text'), $fontStyle);
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
$this->text = SharedText::toUTF8($text);
$matches = preg_split('/({.*?})/', $this->text, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
if (isset($matches[0])) {
$this->text = $matches;
}
}
/**
* Get Text style
*
* @return string|\PhpOffice\PhpWord\Style\Font
*/
public function getFontStyle()
{
return $this->fontStyle;
}
/**
* Get Paragraph style
*
* @return string|\PhpOffice\PhpWord\Style\Paragraph
*/
public function getParagraphStyle()
{
return $this->paragraphStyle;
}
/**
* Get Text content
*
* @return string|array
*/
public function getText()
{
return $this->text;
}
}

View File

@@ -0,0 +1,107 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\Row as RowStyle;
/**
* Table row element
*
* @since 0.8.0
*/
class Row extends AbstractElement
{
/**
* Row height
*
* @var int
*/
private $height = null;
/**
* Row style
*
* @var \PhpOffice\PhpWord\Style\Row
*/
private $style;
/**
* Row cells
*
* @var \PhpOffice\PhpWord\Element\Cell[]
*/
private $cells = array();
/**
* Create a new table row
*
* @param int $height
* @param mixed $style
*/
public function __construct($height = null, $style = null)
{
$this->height = $height;
$this->style = $this->setNewStyle(new RowStyle(), $style, true);
}
/**
* Add a cell
*
* @param int $width
* @param mixed $style
* @return \PhpOffice\PhpWord\Element\Cell
*/
public function addCell($width = null, $style = null)
{
$cell = new Cell($width, $style);
$cell->setParentContainer($this);
$this->cells[] = $cell;
return $cell;
}
/**
* Get all cells
*
* @return \PhpOffice\PhpWord\Element\Cell[]
*/
public function getCells()
{
return $this->cells;
}
/**
* Get row style
*
* @return \PhpOffice\PhpWord\Style\Row
*/
public function getStyle()
{
return $this->style;
}
/**
* Get row height
*
* @return int
*/
public function getHeight()
{
return $this->height;
}
}

View File

@@ -0,0 +1,190 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
/**
* Structured document tag (SDT) element
*
* @since 0.12.0
*/
class SDT extends Text
{
/**
* Form field type: comboBox|dropDownList|date
*
* @var string
*/
private $type;
/**
* Value
*
* @var string|bool|int
*/
private $value;
/**
* CheckBox/DropDown list entries
*
* @var array
*/
private $listItems = array();
/**
* Alias
*
* @var string
*/
private $alias;
/**
* Tag
*
* @var string
*/
private $tag;
/**
* Create new instance
*
* @param string $type
* @param mixed $fontStyle
* @param mixed $paragraphStyle
*/
public function __construct($type, $fontStyle = null, $paragraphStyle = null)
{
parent::__construct(null, $fontStyle, $paragraphStyle);
$this->setType($type);
}
/**
* Get type
*
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* Set type
*
* @param string $value
* @return self
*/
public function setType($value)
{
$enum = array('plainText', 'comboBox', 'dropDownList', 'date');
$this->type = $this->setEnumVal($value, $enum, 'comboBox');
return $this;
}
/**
* Get value
*
* @return string|bool|int
*/
public function getValue()
{
return $this->value;
}
/**
* Set value
*
* @param string|bool|int $value
* @return self
*/
public function setValue($value)
{
$this->value = $value;
return $this;
}
/**
* Get listItems
*
* @return array
*/
public function getListItems()
{
return $this->listItems;
}
/**
* Set listItems
*
* @param array $value
* @return self
*/
public function setListItems($value)
{
$this->listItems = $value;
return $this;
}
/**
* Get tag
*
* @return string
*/
public function getTag()
{
return $this->tag;
}
/**
* Set tag
*
* @param string $tag
* @return self
*/
public function setTag($tag)
{
$this->tag = $tag;
return $this;
}
/**
* Get alias
*
* @return string
*/
public function getAlias()
{
return $this->alias;
}
/**
* Set alias
*
* @param string $alias
* @return self
*/
public function setAlias($alias)
{
$this->alias = $alias;
return $this;
}
}

View File

@@ -0,0 +1,307 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\ComplexType\FootnoteProperties;
use PhpOffice\PhpWord\Style\Section as SectionStyle;
class Section extends AbstractContainer
{
/**
* @var string Container type
*/
protected $container = 'Section';
/**
* Section style
*
* @var \PhpOffice\PhpWord\Style\Section
*/
private $style;
/**
* Section headers, indexed from 1, not zero
*
* @var Header[]
*/
private $headers = array();
/**
* Section footers, indexed from 1, not zero
*
* @var Footer[]
*/
private $footers = array();
/**
* The properties for the footnote of this section
*
* @var FootnoteProperties
*/
private $footnoteProperties;
/**
* Create new instance
*
* @param int $sectionCount
* @param null|array|\PhpOffice\PhpWord\Style $style
*/
public function __construct($sectionCount, $style = null)
{
$this->sectionId = $sectionCount;
$this->setDocPart($this->container, $this->sectionId);
if (null === $style) {
$style = new SectionStyle();
}
$this->style = $this->setNewStyle(new SectionStyle(), $style);
}
/**
* Set section style.
*
* @param array $style
*/
public function setStyle($style = null)
{
if (!is_null($style) && is_array($style)) {
$this->style->setStyleByArray($style);
}
}
/**
* Get section style
*
* @return \PhpOffice\PhpWord\Style\Section
*/
public function getStyle()
{
return $this->style;
}
/**
* Add header
*
* @since 0.10.0
*
* @param string $type
*
* @return Header
*/
public function addHeader($type = Header::AUTO)
{
return $this->addHeaderFooter($type, true);
}
/**
* Add footer
*
* @since 0.10.0
*
* @param string $type
*
* @return Footer
*/
public function addFooter($type = Header::AUTO)
{
return $this->addHeaderFooter($type, false);
}
/**
* Get header elements
*
* @return Header[]
*/
public function getHeaders()
{
return $this->headers;
}
/**
* Get footer elements
*
* @return Footer[]
*/
public function getFooters()
{
return $this->footers;
}
/**
* Get the footnote properties
*
* @return FootnoteProperties
*/
public function getFootnoteProperties()
{
return $this->footnoteProperties;
}
/**
* Get the footnote properties
*
* @deprecated Use the `getFootnoteProperties` method instead
*
* @return FootnoteProperties
*
* @codeCoverageIgnore
*/
public function getFootnotePropoperties()
{
return $this->footnoteProperties;
}
/**
* Set the footnote properties
*
* @param FootnoteProperties $footnoteProperties
*/
public function setFootnoteProperties(FootnoteProperties $footnoteProperties = null)
{
$this->footnoteProperties = $footnoteProperties;
}
/**
* Is there a header for this section that is for the first page only?
*
* If any of the Header instances have a type of Header::FIRST then this method returns true.
* False otherwise.
*
* @return bool
*/
public function hasDifferentFirstPage()
{
foreach ($this->headers as $header) {
if ($header->getType() == Header::FIRST) {
return true;
}
}
foreach ($this->footers as $footer) {
if ($footer->getType() == Header::FIRST) {
return true;
}
}
return false;
}
/**
* Add header/footer
*
* @since 0.10.0
*
* @param string $type
* @param bool $header
*
* @throws \Exception
*
* @return Header|Footer
*/
private function addHeaderFooter($type = Header::AUTO, $header = true)
{
$containerClass = substr(get_class($this), 0, strrpos(get_class($this), '\\')) . '\\' .
($header ? 'Header' : 'Footer');
$collectionArray = $header ? 'headers' : 'footers';
$collection = &$this->$collectionArray;
if (in_array($type, array(Header::AUTO, Header::FIRST, Header::EVEN))) {
$index = count($collection);
/** @var \PhpOffice\PhpWord\Element\AbstractContainer $container Type hint */
$container = new $containerClass($this->sectionId, ++$index, $type);
$container->setPhpWord($this->phpWord);
$collection[$index] = $container;
return $container;
}
throw new \Exception('Invalid header/footer type.');
}
/**
* Set section style
*
* @deprecated 0.12.0
*
* @param array $settings
*
* @codeCoverageIgnore
*/
public function setSettings($settings = null)
{
$this->setStyle($settings);
}
/**
* Get section style
*
* @deprecated 0.12.0
*
* @return \PhpOffice\PhpWord\Style\Section
*
* @codeCoverageIgnore
*/
public function getSettings()
{
return $this->getStyle();
}
/**
* Create header
*
* @deprecated 0.10.0
*
* @return Header
*
* @codeCoverageIgnore
*/
public function createHeader()
{
return $this->addHeader();
}
/**
* Create footer
*
* @deprecated 0.10.0
*
* @return Footer
*
* @codeCoverageIgnore
*/
public function createFooter()
{
return $this->addFooter();
}
/**
* Get footer
*
* @deprecated 0.10.0
*
* @return Footer
*
* @codeCoverageIgnore
*/
public function getFooter()
{
if (empty($this->footers)) {
return null;
}
return $this->footers[1];
}
}

View File

@@ -0,0 +1,88 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\Shape as ShapeStyle;
/**
* Shape element
*
* @since 0.12.0
*/
class Shape extends AbstractElement
{
/**
* Shape type arc|curve|line|polyline|rect|oval
*
* @var string
*/
private $type;
/**
* Shape style
*
* @var \PhpOffice\PhpWord\Style\Shape
*/
private $style;
/**
* Create new instance
*
* @param string $type
* @param mixed $style
*/
public function __construct($type, $style = null)
{
$this->setType($type);
$this->style = $this->setNewStyle(new ShapeStyle(), $style);
}
/**
* Get type
*
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* Set pattern
*
* @param string $value
* @return self
*/
public function setType($value = null)
{
$enum = array('arc', 'curve', 'line', 'polyline', 'rect', 'oval');
$this->type = $this->setEnumVal($value, $enum, null);
return $this;
}
/**
* Get shape style
*
* @return \PhpOffice\PhpWord\Style\Shape
*/
public function getStyle()
{
return $this->style;
}
}

View File

@@ -0,0 +1,169 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\TOC as TOCStyle;
/**
* Table of contents
*/
class TOC extends AbstractElement
{
/**
* TOC style
*
* @var \PhpOffice\PhpWord\Style\TOC
*/
private $TOCStyle;
/**
* Font style
*
* @var \PhpOffice\PhpWord\Style\Font|string
*/
private $fontStyle;
/**
* Min title depth to show
*
* @var int
*/
private $minDepth = 1;
/**
* Max title depth to show
*
* @var int
*/
private $maxDepth = 9;
/**
* Create a new Table-of-Contents Element
*
* @param mixed $fontStyle
* @param array $tocStyle
* @param int $minDepth
* @param int $maxDepth
*/
public function __construct($fontStyle = null, $tocStyle = null, $minDepth = 1, $maxDepth = 9)
{
$this->TOCStyle = new TOCStyle();
if (!is_null($tocStyle) && is_array($tocStyle)) {
$this->TOCStyle->setStyleByArray($tocStyle);
}
if (!is_null($fontStyle) && is_array($fontStyle)) {
$this->fontStyle = new Font();
$this->fontStyle->setStyleByArray($fontStyle);
} else {
$this->fontStyle = $fontStyle;
}
$this->minDepth = $minDepth;
$this->maxDepth = $maxDepth;
}
/**
* Get all titles
*
* @return array
*/
public function getTitles()
{
if (!$this->phpWord instanceof PhpWord) {
return array();
}
$titles = $this->phpWord->getTitles()->getItems();
foreach ($titles as $i => $title) {
/** @var \PhpOffice\PhpWord\Element\Title $title Type hint */
$depth = $title->getDepth();
if ($this->minDepth > $depth) {
unset($titles[$i]);
}
if (($this->maxDepth != 0) && ($this->maxDepth < $depth)) {
unset($titles[$i]);
}
}
return $titles;
}
/**
* Get TOC Style
*
* @return \PhpOffice\PhpWord\Style\TOC
*/
public function getStyleTOC()
{
return $this->TOCStyle;
}
/**
* Get Font Style
*
* @return \PhpOffice\PhpWord\Style\Font|string
*/
public function getStyleFont()
{
return $this->fontStyle;
}
/**
* Set max depth.
*
* @param int $value
*/
public function setMaxDepth($value)
{
$this->maxDepth = $value;
}
/**
* Get Max Depth
*
* @return int Max depth of titles
*/
public function getMaxDepth()
{
return $this->maxDepth;
}
/**
* Set min depth.
*
* @param int $value
*/
public function setMinDepth($value)
{
$this->minDepth = $value;
}
/**
* Get Min Depth
*
* @return int Min depth of titles
*/
public function getMinDepth()
{
return $this->minDepth;
}
}

View File

@@ -0,0 +1,174 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\Table as TableStyle;
/**
* Table element
*/
class Table extends AbstractElement
{
/**
* Table style
*
* @var \PhpOffice\PhpWord\Style\Table
*/
private $style;
/**
* Table rows
*
* @var \PhpOffice\PhpWord\Element\Row[]
*/
private $rows = array();
/**
* Table width
*
* @var int
*/
private $width = null;
/**
* Create a new table
*
* @param mixed $style
*/
public function __construct($style = null)
{
$this->style = $this->setNewStyle(new TableStyle(), $style);
}
/**
* Add a row
*
* @param int $height
* @param mixed $style
* @return \PhpOffice\PhpWord\Element\Row
*/
public function addRow($height = null, $style = null)
{
$row = new Row($height, $style);
$row->setParentContainer($this);
$this->rows[] = $row;
return $row;
}
/**
* Add a cell
*
* @param int $width
* @param mixed $style
* @return \PhpOffice\PhpWord\Element\Cell
*/
public function addCell($width = null, $style = null)
{
$index = count($this->rows) - 1;
$row = $this->rows[$index];
$cell = $row->addCell($width, $style);
return $cell;
}
/**
* Get all rows
*
* @return \PhpOffice\PhpWord\Element\Row[]
*/
public function getRows()
{
return $this->rows;
}
/**
* Get table style
*
* @return \PhpOffice\PhpWord\Style\Table
*/
public function getStyle()
{
return $this->style;
}
/**
* Get table width
*
* @return int
*/
public function getWidth()
{
return $this->width;
}
/**
* Set table width.
*
* @param int $width
*/
public function setWidth($width)
{
$this->width = $width;
}
/**
* Get column count
*
* @return int
*/
public function countColumns()
{
$columnCount = 0;
$rowCount = count($this->rows);
for ($i = 0; $i < $rowCount; $i++) {
/** @var \PhpOffice\PhpWord\Element\Row $row Type hint */
$row = $this->rows[$i];
$cellCount = count($row->getCells());
if ($columnCount < $cellCount) {
$columnCount = $cellCount;
}
}
return $columnCount;
}
/**
* The first declared cell width for each column
*
* @return int[]
*/
public function findFirstDefinedCellWidths()
{
$cellWidths = array();
foreach ($this->rows as $row) {
$cells = $row->getCells();
if (count($cells) <= count($cellWidths)) {
continue;
}
$cellWidths = array();
foreach ($cells as $cell) {
$cellWidths[] = $cell->getWidth();
}
}
return $cellWidths;
}
}

View File

@@ -0,0 +1,153 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Shared\Text as SharedText;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
/**
* Text element
*/
class Text extends AbstractElement
{
/**
* Text content
*
* @var string
*/
protected $text;
/**
* Text style
*
* @var string|\PhpOffice\PhpWord\Style\Font
*/
protected $fontStyle;
/**
* Paragraph style
*
* @var string|\PhpOffice\PhpWord\Style\Paragraph
*/
protected $paragraphStyle;
/**
* Create a new Text Element
*
* @param string $text
* @param mixed $fontStyle
* @param mixed $paragraphStyle
*/
public function __construct($text = null, $fontStyle = null, $paragraphStyle = null)
{
$this->setText($text);
$paragraphStyle = $this->setParagraphStyle($paragraphStyle);
$this->setFontStyle($fontStyle, $paragraphStyle);
}
/**
* Set Text style
*
* @param string|array|\PhpOffice\PhpWord\Style\Font $style
* @param string|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
* @return string|\PhpOffice\PhpWord\Style\Font
*/
public function setFontStyle($style = null, $paragraphStyle = null)
{
if ($style instanceof Font) {
$this->fontStyle = $style;
$this->setParagraphStyle($paragraphStyle);
} elseif (is_array($style)) {
$this->fontStyle = new Font('text', $paragraphStyle);
$this->fontStyle->setStyleByArray($style);
} elseif (null === $style) {
$this->fontStyle = new Font('text', $paragraphStyle);
} else {
$this->fontStyle = $style;
$this->setParagraphStyle($paragraphStyle);
}
return $this->fontStyle;
}
/**
* Get Text style
*
* @return string|\PhpOffice\PhpWord\Style\Font
*/
public function getFontStyle()
{
return $this->fontStyle;
}
/**
* Set Paragraph style
*
* @param string|array|\PhpOffice\PhpWord\Style\Paragraph $style
* @return string|\PhpOffice\PhpWord\Style\Paragraph
*/
public function setParagraphStyle($style = null)
{
if (is_array($style)) {
$this->paragraphStyle = new Paragraph();
$this->paragraphStyle->setStyleByArray($style);
} elseif ($style instanceof Paragraph) {
$this->paragraphStyle = $style;
} elseif (null === $style) {
$this->paragraphStyle = new Paragraph();
} else {
$this->paragraphStyle = $style;
}
return $this->paragraphStyle;
}
/**
* Get Paragraph style
*
* @return string|\PhpOffice\PhpWord\Style\Paragraph
*/
public function getParagraphStyle()
{
return $this->paragraphStyle;
}
/**
* Set text content
*
* @param string $text
* @return self
*/
public function setText($text)
{
$this->text = SharedText::toUTF8($text);
return $this;
}
/**
* Get Text content
*
* @return string
*/
public function getText()
{
return $this->text;
}
}

View File

@@ -0,0 +1,60 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\TextBox as TextBoxStyle;
/**
* TextBox element
*
* @since 0.11.0
*/
class TextBox extends AbstractContainer
{
/**
* @var string Container type
*/
protected $container = 'TextBox';
/**
* TextBox style
*
* @var \PhpOffice\PhpWord\Style\TextBox
*/
private $style;
/**
* Create a new textbox
*
* @param mixed $style
*/
public function __construct($style = null)
{
$this->style = $this->setNewStyle(new TextBoxStyle(), $style);
}
/**
* Get textbox style
*
* @return \PhpOffice\PhpWord\Style\TextBox
*/
public function getStyle()
{
return $this->style;
}
}

View File

@@ -0,0 +1,130 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
/**
* Text break element
*/
class TextBreak extends AbstractElement
{
/**
* Paragraph style
*
* @var string|\PhpOffice\PhpWord\Style\Paragraph
*/
private $paragraphStyle = null;
/**
* Text style
*
* @var string|\PhpOffice\PhpWord\Style\Font
*/
private $fontStyle = null;
/**
* Create a new TextBreak Element
*
* @param mixed $fontStyle
* @param mixed $paragraphStyle
*/
public function __construct($fontStyle = null, $paragraphStyle = null)
{
if (!is_null($paragraphStyle)) {
$paragraphStyle = $this->setParagraphStyle($paragraphStyle);
}
if (!is_null($fontStyle)) {
$this->setFontStyle($fontStyle, $paragraphStyle);
}
}
/**
* Set Text style
*
* @param mixed $style
* @param mixed $paragraphStyle
* @return string|\PhpOffice\PhpWord\Style\Font
*/
public function setFontStyle($style = null, $paragraphStyle = null)
{
if ($style instanceof Font) {
$this->fontStyle = $style;
$this->setParagraphStyle($paragraphStyle);
} elseif (is_array($style)) {
$this->fontStyle = new Font('text', $paragraphStyle);
$this->fontStyle->setStyleByArray($style);
} else {
$this->fontStyle = $style;
$this->setParagraphStyle($paragraphStyle);
}
return $this->fontStyle;
}
/**
* Get Text style
*
* @return string|\PhpOffice\PhpWord\Style\Font
*/
public function getFontStyle()
{
return $this->fontStyle;
}
/**
* Set Paragraph style
*
* @param string|array|\PhpOffice\PhpWord\Style\Paragraph $style
* @return string|\PhpOffice\PhpWord\Style\Paragraph
*/
public function setParagraphStyle($style = null)
{
if (is_array($style)) {
$this->paragraphStyle = new Paragraph();
$this->paragraphStyle->setStyleByArray($style);
} elseif ($style instanceof Paragraph) {
$this->paragraphStyle = $style;
} else {
$this->paragraphStyle = $style;
}
return $this->paragraphStyle;
}
/**
* Get Paragraph style
*
* @return string|\PhpOffice\PhpWord\Style\Paragraph
*/
public function getParagraphStyle()
{
return $this->paragraphStyle;
}
/**
* Has font/paragraph style defined
*
* @return bool
*/
public function hasStyle()
{
return !is_null($this->fontStyle) || !is_null($this->paragraphStyle);
}
}

View File

@@ -0,0 +1,80 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\Paragraph;
/**
* Textrun/paragraph element
*/
class TextRun extends AbstractContainer
{
/**
* @var string Container type
*/
protected $container = 'TextRun';
/**
* Paragraph style
*
* @var string|\PhpOffice\PhpWord\Style\Paragraph
*/
protected $paragraphStyle;
/**
* Create new instance
*
* @param string|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
*/
public function __construct($paragraphStyle = null)
{
$this->paragraphStyle = $this->setParagraphStyle($paragraphStyle);
}
/**
* Get Paragraph style
*
* @return string|\PhpOffice\PhpWord\Style\Paragraph
*/
public function getParagraphStyle()
{
return $this->paragraphStyle;
}
/**
* Set Paragraph style
*
* @param string|array|\PhpOffice\PhpWord\Style\Paragraph $style
* @return string|\PhpOffice\PhpWord\Style\Paragraph
*/
public function setParagraphStyle($style = null)
{
if (is_array($style)) {
$this->paragraphStyle = new Paragraph();
$this->paragraphStyle->setStyleByArray($style);
} elseif ($style instanceof Paragraph) {
$this->paragraphStyle = $style;
} elseif (null === $style) {
$this->paragraphStyle = new Paragraph();
} else {
$this->paragraphStyle = $style;
}
return $this->paragraphStyle;
}
}

View File

@@ -0,0 +1,108 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Shared\Text as SharedText;
use PhpOffice\PhpWord\Style;
/**
* Title element
*/
class Title extends AbstractElement
{
/**
* Title Text content
*
* @var string|TextRun
*/
private $text;
/**
* Title depth
*
* @var int
*/
private $depth = 1;
/**
* Name of the heading style, e.g. 'Heading1'
*
* @var string
*/
private $style;
/**
* Is part of collection
*
* @var bool
*/
protected $collectionRelation = true;
/**
* Create a new Title Element
*
* @param string|TextRun $text
* @param int $depth
*/
public function __construct($text, $depth = 1)
{
if (is_string($text)) {
$this->text = SharedText::toUTF8($text);
} elseif ($text instanceof TextRun) {
$this->text = $text;
} else {
throw new \InvalidArgumentException('Invalid text, should be a string or a TextRun');
}
$this->depth = $depth;
$styleName = $depth === 0 ? 'Title' : "Heading_{$this->depth}";
if (array_key_exists($styleName, Style::getStyles())) {
$this->style = str_replace('_', '', $styleName);
}
}
/**
* Get Title Text content
*
* @return string
*/
public function getText()
{
return $this->text;
}
/**
* Get depth
*
* @return int
*/
public function getDepth()
{
return $this->depth;
}
/**
* Get Title style
*
* @return string
*/
public function getStyle()
{
return $this->style;
}
}

View File

@@ -0,0 +1,101 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
/**
* TrackChange element
* @see http://datypic.com/sc/ooxml/t-w_CT_TrackChange.html
* @see http://datypic.com/sc/ooxml/t-w_CT_RunTrackChange.html
*/
class TrackChange extends AbstractContainer
{
const INSERTED = 'INSERTED';
const DELETED = 'DELETED';
/**
* @var string Container type
*/
protected $container = 'TrackChange';
/**
* The type of change, (insert or delete), not applicable for PhpOffice\PhpWord\Element\Comment
*
* @var string
*/
private $changeType;
/**
* Author
*
* @var string
*/
private $author;
/**
* Date
*
* @var \DateTime
*/
private $date;
/**
* Create a new TrackChange Element
*
* @param string $changeType
* @param string $author
* @param null|int|bool|\DateTime $date
*/
public function __construct($changeType = null, $author = null, $date = null)
{
$this->changeType = $changeType;
$this->author = $author;
if ($date !== null && $date !== false) {
$this->date = ($date instanceof \DateTime) ? $date : new \DateTime('@' . $date);
}
}
/**
* Get TrackChange Author
*
* @return string
*/
public function getAuthor()
{
return $this->author;
}
/**
* Get TrackChange Date
*
* @return \DateTime
*/
public function getDate()
{
return $this->date;
}
/**
* Get the Change type
*
* @return string
*/
public function getChangeType()
{
return $this->changeType;
}
}

View File

@@ -0,0 +1,46 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Escaper;
/**
* @since 0.13.0
*
* @codeCoverageIgnore
*/
abstract class AbstractEscaper implements EscaperInterface
{
/**
* @param string $input
*
* @return string
*/
abstract protected function escapeSingleValue($input);
public function escape($input)
{
if (is_array($input)) {
foreach ($input as &$item) {
$item = $this->escapeSingleValue($item);
}
} else {
$input = $this->escapeSingleValue($input);
}
return $input;
}
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Escaper;
/**
* @since 0.13.0
*
* @codeCoverageIgnore
*/
interface EscaperInterface
{
/**
* @param mixed $input
*
* @return mixed
*/
public function escape($input);
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Escaper;
/**
* @since 0.13.0
*
* @codeCoverageIgnore
*/
class RegExp extends AbstractEscaper
{
const REG_EXP_DELIMITER = '/';
protected function escapeSingleValue($input)
{
return self::REG_EXP_DELIMITER . preg_quote($input, self::REG_EXP_DELIMITER) . self::REG_EXP_DELIMITER . 'u';
}
}

View File

@@ -0,0 +1,97 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Escaper;
/**
* @since 0.13.0
*
* @codeCoverageIgnore
*/
class Rtf extends AbstractEscaper
{
protected function escapeAsciiCharacter($code)
{
if ($code == 9) {
return '{\\tab}';
}
if (0x20 > $code || $code >= 0x80) {
return '{\\u' . $code . '}';
}
if ($code == 123 || $code == 125 || $code == 92) { // open or close brace or backslash
return '\\' . chr($code);
}
return chr($code);
}
protected function escapeMultibyteCharacter($code)
{
return '\\uc0{\\u' . $code . '}';
}
/**
* @see http://www.randomchaos.com/documents/?source=php_and_unicode
* @param string $input
*/
protected function escapeSingleValue($input)
{
$escapedValue = '';
$numberOfBytes = 1;
$bytes = array();
for ($i = 0; $i < strlen($input); ++$i) {
$character = $input[$i];
$asciiCode = ord($character);
if ($asciiCode < 128) {
$escapedValue .= $this->escapeAsciiCharacter($asciiCode);
} else {
if (0 == count($bytes)) {
if ($asciiCode < 224) {
$numberOfBytes = 2;
} elseif ($asciiCode < 240) {
$numberOfBytes = 3;
} elseif ($asciiCode < 248) {
$numberOfBytes = 4;
}
}
$bytes[] = $asciiCode;
if ($numberOfBytes == count($bytes)) {
if (4 == $numberOfBytes) {
$multibyteCode = ($bytes[0] % 8) * 262144 + ($bytes[1] % 64) * 4096 + ($bytes[2] % 64) * 64 + ($bytes[3] % 64);
} elseif (3 == $numberOfBytes) {
$multibyteCode = ($bytes[0] % 16) * 4096 + ($bytes[1] % 64) * 64 + ($bytes[2] % 64);
} else {
$multibyteCode = ($bytes[0] % 32) * 64 + ($bytes[1] % 64);
}
if (65279 != $multibyteCode) {
$escapedValue .= $multibyteCode < 128 ? $this->escapeAsciiCharacter($multibyteCode) : $this->escapeMultibyteCharacter($multibyteCode);
}
$numberOfBytes = 1;
$bytes = array();
}
}
}
return $escapedValue;
}
}

View File

@@ -0,0 +1,32 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Escaper;
/**
* @since 0.13.0
*
* @codeCoverageIgnore
*/
class Xml extends AbstractEscaper
{
protected function escapeSingleValue($input)
{
// todo: omit encoding parameter after migration onto PHP 5.4
return htmlspecialchars($input, ENT_QUOTES, 'UTF-8');
}
}

View File

@@ -0,0 +1,39 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Exception;
/**
* @since 0.12.0
*/
final class CopyFileException extends Exception
{
/**
* @param string $source The fully qualified source file name
* @param string $destination The fully qualified destination file name
* @param int $code The user defined exception code
* @param \Exception $previous The previous exception used for the exception chaining
*/
final public function __construct($source, $destination, $code = 0, \Exception $previous = null)
{
parent::__construct(
sprintf('Could not copy \'%s\' file to \'%s\'.', $source, $destination),
$code,
$previous
);
}
}

View File

@@ -0,0 +1,37 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Exception;
/**
* @since 0.12.0
*/
final class CreateTemporaryFileException extends Exception
{
/**
* @param int $code The user defined exception code
* @param \Exception $previous The previous exception used for the exception chaining
*/
final public function __construct($code = 0, \Exception $previous = null)
{
parent::__construct(
'Could not create a temporary file with unique name in the specified directory.',
$code,
$previous
);
}
}

View File

@@ -0,0 +1,25 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Exception;
/**
* General exception
*/
class Exception extends \Exception
{
}

View File

@@ -0,0 +1,25 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Exception;
/**
* Exception used for when an image is not found
*/
class InvalidImageException extends Exception
{
}

View File

@@ -0,0 +1,25 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Exception;
/**
* Exception used for when an image is not found
*/
class InvalidObjectException extends Exception
{
}

View File

@@ -0,0 +1,27 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Exception;
use InvalidArgumentException;
/**
* Exception used for when a style value is invalid
*/
class InvalidStyleException extends InvalidArgumentException
{
}

View File

@@ -0,0 +1,25 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Exception;
/**
* Exception used for when an image type is unsupported
*/
class UnsupportedImageTypeException extends Exception
{
}

View File

@@ -0,0 +1,108 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord;
use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\Reader\ReaderInterface;
use PhpOffice\PhpWord\Writer\WriterInterface;
abstract class IOFactory
{
/**
* Create new writer
*
* @param PhpWord $phpWord
* @param string $name
*
* @throws \PhpOffice\PhpWord\Exception\Exception
*
* @return WriterInterface
*/
public static function createWriter(PhpWord $phpWord, $name = 'Word2007')
{
if ($name !== 'WriterInterface' && !in_array($name, array('ODText', 'RTF', 'Word2007', 'HTML', 'PDF'), true)) {
throw new Exception("\"{$name}\" is not a valid writer.");
}
$fqName = "PhpOffice\\PhpWord\\Writer\\{$name}";
return new $fqName($phpWord);
}
/**
* Create new reader
*
* @param string $name
*
* @throws Exception
*
* @return ReaderInterface
*/
public static function createReader($name = 'Word2007')
{
return self::createObject('Reader', $name);
}
/**
* Create new object
*
* @param string $type
* @param string $name
* @param \PhpOffice\PhpWord\PhpWord $phpWord
*
* @throws \PhpOffice\PhpWord\Exception\Exception
*
* @return \PhpOffice\PhpWord\Writer\WriterInterface|\PhpOffice\PhpWord\Reader\ReaderInterface
*/
private static function createObject($type, $name, $phpWord = null)
{
$class = "PhpOffice\\PhpWord\\{$type}\\{$name}";
if (class_exists($class) && self::isConcreteClass($class)) {
return new $class($phpWord);
}
throw new Exception("\"{$name}\" is not a valid {$type}.");
}
/**
* Loads PhpWord from file
*
* @param string $filename The name of the file
* @param string $readerName
* @return \PhpOffice\PhpWord\PhpWord $phpWord
*/
public static function load($filename, $readerName = 'Word2007')
{
/** @var \PhpOffice\PhpWord\Reader\ReaderInterface $reader */
$reader = self::createReader($readerName);
return $reader->load($filename);
}
/**
* Check if it's a concrete class (not abstract nor interface)
*
* @param string $class
* @return bool
*/
private static function isConcreteClass($class)
{
$reflection = new \ReflectionClass($class);
return !$reflection->isAbstract() && !$reflection->isInterface();
}
}

View File

@@ -0,0 +1,365 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord;
use PhpOffice\PhpWord\Element\Image;
use PhpOffice\PhpWord\Exception\Exception;
/**
* Media collection
*/
class Media
{
/**
* Media elements
*
* @var array
*/
private static $elements = array();
/**
* Add new media element
*
* @since 0.10.0
* @since 0.9.2
*
* @param string $container section|headerx|footerx|footnote|endnote
* @param string $mediaType image|object|link
* @param string $source
* @param \PhpOffice\PhpWord\Element\Image $image
*
* @throws \PhpOffice\PhpWord\Exception\Exception
*
* @return int
*/
public static function addElement($container, $mediaType, $source, Image $image = null)
{
// Assign unique media Id and initiate media container if none exists
$mediaId = md5($container . $source);
if (!isset(self::$elements[$container])) {
self::$elements[$container] = array();
}
// Add media if not exists or point to existing media
if (!isset(self::$elements[$container][$mediaId])) {
$mediaCount = self::countElements($container);
$mediaTypeCount = self::countElements($container, $mediaType);
$mediaTypeCount++;
$rId = ++$mediaCount;
$target = null;
$mediaData = array('mediaIndex' => $mediaTypeCount);
switch ($mediaType) {
// Images
case 'image':
if (is_null($image)) {
throw new Exception('Image object not assigned.');
}
$isMemImage = $image->isMemImage();
$extension = $image->getImageExtension();
$mediaData['imageExtension'] = $extension;
$mediaData['imageType'] = $image->getImageType();
if ($isMemImage) {
$mediaData['isMemImage'] = true;
$mediaData['createFunction'] = $image->getImageCreateFunction();
$mediaData['imageFunction'] = $image->getImageFunction();
}
$target = "{$container}_image{$mediaTypeCount}.{$extension}";
$image->setTarget($target);
$image->setMediaIndex($mediaTypeCount);
break;
// Objects
case 'object':
$target = "{$container}_oleObject{$mediaTypeCount}.bin";
break;
// Links
case 'link':
$target = $source;
break;
}
$mediaData['source'] = $source;
$mediaData['target'] = $target;
$mediaData['type'] = $mediaType;
$mediaData['rID'] = $rId;
self::$elements[$container][$mediaId] = $mediaData;
return $rId;
}
$mediaData = self::$elements[$container][$mediaId];
if (!is_null($image)) {
$image->setTarget($mediaData['target']);
$image->setMediaIndex($mediaData['mediaIndex']);
}
return $mediaData['rID'];
}
/**
* Get media elements count
*
* @param string $container section|headerx|footerx|footnote|endnote
* @param string $mediaType image|object|link
* @return int
* @since 0.10.0
*/
public static function countElements($container, $mediaType = null)
{
$mediaCount = 0;
if (isset(self::$elements[$container])) {
foreach (self::$elements[$container] as $mediaData) {
if (!is_null($mediaType)) {
if ($mediaType == $mediaData['type']) {
$mediaCount++;
}
} else {
$mediaCount++;
}
}
}
return $mediaCount;
}
/**
* Get media elements
*
* @param string $container section|headerx|footerx|footnote|endnote
* @param string $type image|object|link
* @return array
* @since 0.10.0
*/
public static function getElements($container, $type = null)
{
$elements = array();
// If header/footer, search for headerx and footerx where x is number
if ($container == 'header' || $container == 'footer') {
foreach (self::$elements as $key => $val) {
if (substr($key, 0, 6) == $container) {
$elements[$key] = $val;
}
}
return $elements;
}
if (!isset(self::$elements[$container])) {
return $elements;
}
return self::getElementsByType($container, $type);
}
/**
* Get elements by media type
*
* @param string $container section|footnote|endnote
* @param string $type image|object|link
* @return array
* @since 0.11.0 Splitted from `getElements` to reduce complexity
*/
private static function getElementsByType($container, $type = null)
{
$elements = array();
foreach (self::$elements[$container] as $key => $data) {
if ($type !== null) {
if ($type == $data['type']) {
$elements[$key] = $data;
}
} else {
$elements[$key] = $data;
}
}
return $elements;
}
/**
* Reset media elements
*/
public static function resetElements()
{
self::$elements = array();
}
/**
* Add new Section Media Element
*
* @deprecated 0.10.0
*
* @param string $src
* @param string $type
* @param \PhpOffice\PhpWord\Element\Image $image
*
* @return int
*
* @codeCoverageIgnore
*/
public static function addSectionMediaElement($src, $type, Image $image = null)
{
return self::addElement('section', $type, $src, $image);
}
/**
* Add new Section Link Element
*
* @deprecated 0.10.0
*
* @param string $linkSrc
*
* @return int
*
* @codeCoverageIgnore
*/
public static function addSectionLinkElement($linkSrc)
{
return self::addElement('section', 'link', $linkSrc);
}
/**
* Get Section Media Elements
*
* @deprecated 0.10.0
*
* @param string $key
*
* @return array
*
* @codeCoverageIgnore
*/
public static function getSectionMediaElements($key = null)
{
return self::getElements('section', $key);
}
/**
* Get Section Media Elements Count
*
* @deprecated 0.10.0
*
* @param string $key
*
* @return int
*
* @codeCoverageIgnore
*/
public static function countSectionMediaElements($key = null)
{
return self::countElements('section', $key);
}
/**
* Add new Header Media Element
*
* @deprecated 0.10.0
*
* @param int $headerCount
* @param string $src
* @param \PhpOffice\PhpWord\Element\Image $image
*
* @return int
*
* @codeCoverageIgnore
*/
public static function addHeaderMediaElement($headerCount, $src, Image $image = null)
{
return self::addElement("header{$headerCount}", 'image', $src, $image);
}
/**
* Get Header Media Elements Count
*
* @deprecated 0.10.0
*
* @param string $key
*
* @return int
*
* @codeCoverageIgnore
*/
public static function countHeaderMediaElements($key)
{
return self::countElements($key);
}
/**
* Get Header Media Elements
*
* @deprecated 0.10.0
*
* @return array
*
* @codeCoverageIgnore
*/
public static function getHeaderMediaElements()
{
return self::getElements('header');
}
/**
* Add new Footer Media Element
*
* @deprecated 0.10.0
*
* @param int $footerCount
* @param string $src
* @param \PhpOffice\PhpWord\Element\Image $image
*
* @return int
*
* @codeCoverageIgnore
*/
public static function addFooterMediaElement($footerCount, $src, Image $image = null)
{
return self::addElement("footer{$footerCount}", 'image', $src, $image);
}
/**
* Get Footer Media Elements Count
*
* @deprecated 0.10.0
*
* @param string $key
*
* @return int
*
* @codeCoverageIgnore
*/
public static function countFooterMediaElements($key)
{
return self::countElements($key);
}
/**
* Get Footer Media Elements
*
* @deprecated 0.10.0
*
* @return array
*
* @codeCoverageIgnore
*/
public static function getFooterMediaElements()
{
return self::getElements('footer');
}
}

View File

@@ -0,0 +1,62 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Metadata;
/**
* Compatibility setting class
*
* @since 0.12.0
* @see http://www.datypic.com/sc/ooxml/t-w_CT_Compat.html
*/
class Compatibility
{
/**
* OOXML version
*
* 12 = 2007
* 14 = 2010
* 15 = 2013
*
* @var int
* @see http://msdn.microsoft.com/en-us/library/dd909048%28v=office.12%29.aspx
*/
private $ooxmlVersion = 12;
/**
* Get OOXML version
*
* @return int
*/
public function getOoxmlVersion()
{
return $this->ooxmlVersion;
}
/**
* Set OOXML version
*
* @param int $value
* @return self
*/
public function setOoxmlVersion($value)
{
$this->ooxmlVersion = $value;
return $this;
}
}

View File

@@ -0,0 +1,581 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Metadata;
/**
* Document information
*/
class DocInfo
{
/** @const string Property type constants */
const PROPERTY_TYPE_BOOLEAN = 'b';
const PROPERTY_TYPE_INTEGER = 'i';
const PROPERTY_TYPE_FLOAT = 'f';
const PROPERTY_TYPE_DATE = 'd';
const PROPERTY_TYPE_STRING = 's';
const PROPERTY_TYPE_UNKNOWN = 'u';
/**
* Creator
*
* @var string
*/
private $creator;
/**
* LastModifiedBy
*
* @var string
*/
private $lastModifiedBy;
/**
* Created
*
* @var int
*/
private $created;
/**
* Modified
*
* @var int
*/
private $modified;
/**
* Title
*
* @var string
*/
private $title;
/**
* Description
*
* @var string
*/
private $description;
/**
* Subject
*
* @var string
*/
private $subject;
/**
* Keywords
*
* @var string
*/
private $keywords;
/**
* Category
*
* @var string
*/
private $category;
/**
* Company
*
* @var string
*/
private $company;
/**
* Manager
*
* @var string
*/
private $manager;
/**
* Custom Properties
*
* @var array
*/
private $customProperties = array();
/**
* Create new instance
*/
public function __construct()
{
$this->creator = '';
$this->lastModifiedBy = $this->creator;
$this->created = time();
$this->modified = time();
$this->title = '';
$this->subject = '';
$this->description = '';
$this->keywords = '';
$this->category = '';
$this->company = '';
$this->manager = '';
}
/**
* Get Creator
*
* @return string
*/
public function getCreator()
{
return $this->creator;
}
/**
* Set Creator
*
* @param string $value
* @return self
*/
public function setCreator($value = '')
{
$this->creator = $this->setValue($value, '');
return $this;
}
/**
* Get Last Modified By
*
* @return string
*/
public function getLastModifiedBy()
{
return $this->lastModifiedBy;
}
/**
* Set Last Modified By
*
* @param string $value
* @return self
*/
public function setLastModifiedBy($value = '')
{
$this->lastModifiedBy = $this->setValue($value, $this->creator);
return $this;
}
/**
* Get Created
*
* @return int
*/
public function getCreated()
{
return $this->created;
}
/**
* Set Created
*
* @param int $value
* @return self
*/
public function setCreated($value = null)
{
$this->created = $this->setValue($value, time());
return $this;
}
/**
* Get Modified
*
* @return int
*/
public function getModified()
{
return $this->modified;
}
/**
* Set Modified
*
* @param int $value
* @return self
*/
public function setModified($value = null)
{
$this->modified = $this->setValue($value, time());
return $this;
}
/**
* Get Title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set Title
*
* @param string $value
* @return self
*/
public function setTitle($value = '')
{
$this->title = $this->setValue($value, '');
return $this;
}
/**
* Get Description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set Description
*
* @param string $value
* @return self
*/
public function setDescription($value = '')
{
$this->description = $this->setValue($value, '');
return $this;
}
/**
* Get Subject
*
* @return string
*/
public function getSubject()
{
return $this->subject;
}
/**
* Set Subject
*
* @param string $value
* @return self
*/
public function setSubject($value = '')
{
$this->subject = $this->setValue($value, '');
return $this;
}
/**
* Get Keywords
*
* @return string
*/
public function getKeywords()
{
return $this->keywords;
}
/**
* Set Keywords
*
* @param string $value
* @return self
*/
public function setKeywords($value = '')
{
$this->keywords = $this->setValue($value, '');
return $this;
}
/**
* Get Category
*
* @return string
*/
public function getCategory()
{
return $this->category;
}
/**
* Set Category
*
* @param string $value
* @return self
*/
public function setCategory($value = '')
{
$this->category = $this->setValue($value, '');
return $this;
}
/**
* Get Company
*
* @return string
*/
public function getCompany()
{
return $this->company;
}
/**
* Set Company
*
* @param string $value
* @return self
*/
public function setCompany($value = '')
{
$this->company = $this->setValue($value, '');
return $this;
}
/**
* Get Manager
*
* @return string
*/
public function getManager()
{
return $this->manager;
}
/**
* Set Manager
*
* @param string $value
* @return self
*/
public function setManager($value = '')
{
$this->manager = $this->setValue($value, '');
return $this;
}
/**
* Get a List of Custom Property Names
*
* @return array of string
*/
public function getCustomProperties()
{
return array_keys($this->customProperties);
}
/**
* Check if a Custom Property is defined
*
* @param string $propertyName
* @return bool
*/
public function isCustomPropertySet($propertyName)
{
return isset($this->customProperties[$propertyName]);
}
/**
* Get a Custom Property Value
*
* @param string $propertyName
* @return mixed
*/
public function getCustomPropertyValue($propertyName)
{
if ($this->isCustomPropertySet($propertyName)) {
return $this->customProperties[$propertyName]['value'];
}
return null;
}
/**
* Get a Custom Property Type
*
* @param string $propertyName
* @return string
*/
public function getCustomPropertyType($propertyName)
{
if ($this->isCustomPropertySet($propertyName)) {
return $this->customProperties[$propertyName]['type'];
}
return null;
}
/**
* Set a Custom Property
*
* @param string $propertyName
* @param mixed $propertyValue
* @param string $propertyType
* 'i': Integer
* 'f': Floating Point
* 's': String
* 'd': Date/Time
* 'b': Boolean
* @return self
*/
public function setCustomProperty($propertyName, $propertyValue = '', $propertyType = null)
{
$propertyTypes = array(
self::PROPERTY_TYPE_INTEGER,
self::PROPERTY_TYPE_FLOAT,
self::PROPERTY_TYPE_STRING,
self::PROPERTY_TYPE_DATE,
self::PROPERTY_TYPE_BOOLEAN,
);
if (($propertyType === null) || (!in_array($propertyType, $propertyTypes))) {
if ($propertyValue === null) {
$propertyType = self::PROPERTY_TYPE_STRING;
} elseif (is_float($propertyValue)) {
$propertyType = self::PROPERTY_TYPE_FLOAT;
} elseif (is_int($propertyValue)) {
$propertyType = self::PROPERTY_TYPE_INTEGER;
} elseif (is_bool($propertyValue)) {
$propertyType = self::PROPERTY_TYPE_BOOLEAN;
} elseif ($propertyValue instanceof \DateTime) {
$propertyType = self::PROPERTY_TYPE_DATE;
} else {
$propertyType = self::PROPERTY_TYPE_STRING;
}
}
$this->customProperties[$propertyName] = array(
'value' => $propertyValue,
'type' => $propertyType,
);
return $this;
}
/**
* Convert document property based on type
*
* @param string $propertyValue
* @param string $propertyType
* @return mixed
*/
public static function convertProperty($propertyValue, $propertyType)
{
$conversion = self::getConversion($propertyType);
switch ($conversion) {
case 'empty': // Empty
return '';
case 'null': // Null
return null;
case 'int': // Signed integer
return (int) $propertyValue;
case 'uint': // Unsigned integer
return abs((int) $propertyValue);
case 'float': // Float
return (float) $propertyValue;
case 'date': // Date
return strtotime($propertyValue);
case 'bool': // Boolean
return $propertyValue == 'true';
}
return $propertyValue;
}
/**
* Convert document property type
*
* @param string $propertyType
* @return string
*/
public static function convertPropertyType($propertyType)
{
$typeGroups = array(
self::PROPERTY_TYPE_INTEGER => array('i1', 'i2', 'i4', 'i8', 'int', 'ui1', 'ui2', 'ui4', 'ui8', 'uint'),
self::PROPERTY_TYPE_FLOAT => array('r4', 'r8', 'decimal'),
self::PROPERTY_TYPE_STRING => array('empty', 'null', 'lpstr', 'lpwstr', 'bstr'),
self::PROPERTY_TYPE_DATE => array('date', 'filetime'),
self::PROPERTY_TYPE_BOOLEAN => array('bool'),
);
foreach ($typeGroups as $groupId => $groupMembers) {
if (in_array($propertyType, $groupMembers)) {
return $groupId;
}
}
return self::PROPERTY_TYPE_UNKNOWN;
}
/**
* Set default for null and empty value
*
* @param mixed $value
* @param mixed $default
* @return mixed
*/
private function setValue($value, $default)
{
if ($value === null || $value == '') {
$value = $default;
}
return $value;
}
/**
* Get conversion model depending on property type
*
* @param string $propertyType
* @return string
*/
private static function getConversion($propertyType)
{
$conversions = array(
'empty' => array('empty'),
'null' => array('null'),
'int' => array('i1', 'i2', 'i4', 'i8', 'int'),
'uint' => array('ui1', 'ui2', 'ui4', 'ui8', 'uint'),
'float' => array('r4', 'r8', 'decimal'),
'bool' => array('bool'),
'date' => array('date', 'filetime'),
);
foreach ($conversions as $conversion => $types) {
if (in_array($propertyType, $types)) {
return $conversion;
}
}
return 'string';
}
}

View File

@@ -0,0 +1,199 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Metadata;
use PhpOffice\PhpWord\Shared\Microsoft\PasswordEncoder;
use PhpOffice\PhpWord\SimpleType\DocProtect;
/**
* Document protection class
*
* @since 0.12.0
* @see http://www.datypic.com/sc/ooxml/t-w_CT_DocProtect.html
*/
class Protection
{
/**
* Editing restriction none|readOnly|comments|trackedChanges|forms
*
* @var string
* @see http://www.datypic.com/sc/ooxml/a-w_edit-1.html
*/
private $editing;
/**
* password
*
* @var string
*/
private $password;
/**
* Iterations to Run Hashing Algorithm
*
* @var int
*/
private $spinCount = 100000;
/**
* Cryptographic Hashing Algorithm (see constants defined in \PhpOffice\PhpWord\Shared\Microsoft\PasswordEncoder)
*
* @var string
*/
private $algorithm = PasswordEncoder::ALGORITHM_SHA_1;
/**
* Salt for Password Verifier
*
* @var string
*/
private $salt;
/**
* Create a new instance
*
* @param string $editing
*/
public function __construct($editing = null)
{
if ($editing != null) {
$this->setEditing($editing);
}
}
/**
* Get editing protection
*
* @return string
*/
public function getEditing()
{
return $this->editing;
}
/**
* Set editing protection
*
* @param string $editing Any value of \PhpOffice\PhpWord\SimpleType\DocProtect
* @return self
*/
public function setEditing($editing = null)
{
DocProtect::validate($editing);
$this->editing = $editing;
return $this;
}
/**
* Get password
*
* @return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Set password
*
* @param string $password
* @return self
*/
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
* Get count for hash iterations
*
* @return int
*/
public function getSpinCount()
{
return $this->spinCount;
}
/**
* Set count for hash iterations
*
* @param int $spinCount
* @return self
*/
public function setSpinCount($spinCount)
{
$this->spinCount = $spinCount;
return $this;
}
/**
* Get algorithm
*
* @return string
*/
public function getAlgorithm()
{
return $this->algorithm;
}
/**
* Set algorithm
*
* @param string $algorithm
* @return self
*/
public function setAlgorithm($algorithm)
{
$this->algorithm = $algorithm;
return $this;
}
/**
* Get salt
*
* @return string
*/
public function getSalt()
{
return $this->salt;
}
/**
* Set salt. Salt HAS to be 16 characters, or an exception will be thrown.
*
* @param string $salt
* @throws \InvalidArgumentException
* @return self
*/
public function setSalt($salt)
{
if ($salt !== null && strlen($salt) !== 16) {
throw new \InvalidArgumentException('salt has to be of exactly 16 bytes length');
}
$this->salt = $salt;
return $this;
}
}

View File

@@ -0,0 +1,480 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Metadata;
use PhpOffice\PhpWord\ComplexType\ProofState;
use PhpOffice\PhpWord\ComplexType\TrackChangesView;
use PhpOffice\PhpWord\SimpleType\Zoom;
use PhpOffice\PhpWord\Style\Language;
/**
* Setting class
*
* @since 0.14.0
* @see http://www.datypic.com/sc/ooxml/t-w_CT_Settings.html
*/
class Settings
{
/**
* Magnification Setting
*
* @see http://www.datypic.com/sc/ooxml/e-w_zoom-1.html
* @var mixed either integer, in which case it treated as a percent, or one of PhpOffice\PhpWord\SimpleType\Zoom
*/
private $zoom = 100;
/**
* Mirror Page Margins
*
* @see http://www.datypic.com/sc/ooxml/e-w_mirrorMargins-1.html
* @var bool
*/
private $mirrorMargins;
/**
* Hide spelling errors
*
* @var bool
*/
private $hideSpellingErrors = false;
/**
* Hide grammatical errors
*
* @var bool
*/
private $hideGrammaticalErrors = false;
/**
* Visibility of Annotation Types
*
* @var TrackChangesView
*/
private $revisionView;
/**
* Track Revisions to Document
*
* @var bool
*/
private $trackRevisions = false;
/**
* Do Not Use Move Syntax When Tracking Revisions
*
* @var bool
*/
private $doNotTrackMoves = false;
/**
* Do Not Track Formatting Revisions When Tracking Revisions
*
* @var bool
*/
private $doNotTrackFormatting = false;
/**
* Spelling and Grammatical Checking State
*
* @var \PhpOffice\PhpWord\ComplexType\ProofState
*/
private $proofState;
/**
* Document Editing Restrictions
*
* @var \PhpOffice\PhpWord\Metadata\Protection
*/
private $documentProtection;
/**
* Enables different header for odd and even pages.
*
* @var bool
*/
private $evenAndOddHeaders = false;
/**
* Theme Font Languages
*
* @var Language
*/
private $themeFontLang;
/**
* Automatically Recalculate Fields on Open
*
* @var bool
*/
private $updateFields = false;
/**
* Radix Point for Field Code Evaluation
*
* @var string
*/
private $decimalSymbol = '.';
/**
* Automatically hyphenate document contents when displayed
*
* @var bool|null
*/
private $autoHyphenation;
/**
* Maximum number of consecutively hyphenated lines
*
* @var int|null
*/
private $consecutiveHyphenLimit;
/**
* The allowed amount of whitespace before hyphenation is applied
* @var float|null
*/
private $hyphenationZone;
/**
* Do not hyphenate words in all capital letters
* @var bool|null
*/
private $doNotHyphenateCaps;
/**
* @return Protection
*/
public function getDocumentProtection()
{
if ($this->documentProtection == null) {
$this->documentProtection = new Protection();
}
return $this->documentProtection;
}
/**
* @param Protection $documentProtection
*/
public function setDocumentProtection($documentProtection)
{
$this->documentProtection = $documentProtection;
}
/**
* @return ProofState
*/
public function getProofState()
{
if ($this->proofState == null) {
$this->proofState = new ProofState();
}
return $this->proofState;
}
/**
* @param ProofState $proofState
*/
public function setProofState($proofState)
{
$this->proofState = $proofState;
}
/**
* Are spelling errors hidden
*
* @return bool
*/
public function hasHideSpellingErrors()
{
return $this->hideSpellingErrors;
}
/**
* Hide spelling errors
*
* @param bool $hideSpellingErrors
*/
public function setHideSpellingErrors($hideSpellingErrors)
{
$this->hideSpellingErrors = $hideSpellingErrors === null ? true : $hideSpellingErrors;
}
/**
* Are grammatical errors hidden
*
* @return bool
*/
public function hasHideGrammaticalErrors()
{
return $this->hideGrammaticalErrors;
}
/**
* Hide grammatical errors
*
* @param bool $hideGrammaticalErrors
*/
public function setHideGrammaticalErrors($hideGrammaticalErrors)
{
$this->hideGrammaticalErrors = $hideGrammaticalErrors === null ? true : $hideGrammaticalErrors;
}
/**
* @return bool
*/
public function hasEvenAndOddHeaders()
{
return $this->evenAndOddHeaders;
}
/**
* @param bool $evenAndOddHeaders
*/
public function setEvenAndOddHeaders($evenAndOddHeaders)
{
$this->evenAndOddHeaders = $evenAndOddHeaders === null ? true : $evenAndOddHeaders;
}
/**
* Get the Visibility of Annotation Types
*
* @return \PhpOffice\PhpWord\ComplexType\TrackChangesView
*/
public function getRevisionView()
{
return $this->revisionView;
}
/**
* Set the Visibility of Annotation Types
*
* @param TrackChangesView $trackChangesView
*/
public function setRevisionView(TrackChangesView $trackChangesView = null)
{
$this->revisionView = $trackChangesView;
}
/**
* @return bool
*/
public function hasTrackRevisions()
{
return $this->trackRevisions;
}
/**
* @param bool $trackRevisions
*/
public function setTrackRevisions($trackRevisions)
{
$this->trackRevisions = $trackRevisions === null ? true : $trackRevisions;
}
/**
* @return bool
*/
public function hasDoNotTrackMoves()
{
return $this->doNotTrackMoves;
}
/**
* @param bool $doNotTrackMoves
*/
public function setDoNotTrackMoves($doNotTrackMoves)
{
$this->doNotTrackMoves = $doNotTrackMoves === null ? true : $doNotTrackMoves;
}
/**
* @return bool
*/
public function hasDoNotTrackFormatting()
{
return $this->doNotTrackFormatting;
}
/**
* @param bool $doNotTrackFormatting
*/
public function setDoNotTrackFormatting($doNotTrackFormatting)
{
$this->doNotTrackFormatting = $doNotTrackFormatting === null ? true : $doNotTrackFormatting;
}
/**
* @return mixed
*/
public function getZoom()
{
return $this->zoom;
}
/**
* @param mixed $zoom
*/
public function setZoom($zoom)
{
if (is_numeric($zoom)) {
// zoom is a percentage
$this->zoom = $zoom;
} else {
Zoom::validate($zoom);
$this->zoom = $zoom;
}
}
/**
* @return bool
*/
public function hasMirrorMargins()
{
return $this->mirrorMargins;
}
/**
* @param bool $mirrorMargins
*/
public function setMirrorMargins($mirrorMargins)
{
$this->mirrorMargins = $mirrorMargins;
}
/**
* Returns the Language
*
* @return Language
*/
public function getThemeFontLang()
{
return $this->themeFontLang;
}
/**
* sets the Language for this document
*
* @param Language $themeFontLang
*/
public function setThemeFontLang($themeFontLang)
{
$this->themeFontLang = $themeFontLang;
}
/**
* @return bool
*/
public function hasUpdateFields()
{
return $this->updateFields;
}
/**
* @param bool $updateFields
*/
public function setUpdateFields($updateFields)
{
$this->updateFields = $updateFields === null ? false : $updateFields;
}
/**
* Returns the Radix Point for Field Code Evaluation
*
* @return string
*/
public function getDecimalSymbol()
{
return $this->decimalSymbol;
}
/**
* sets the Radix Point for Field Code Evaluation
*
* @param string $decimalSymbol
*/
public function setDecimalSymbol($decimalSymbol)
{
$this->decimalSymbol = $decimalSymbol;
}
/**
* @return bool|null
*/
public function hasAutoHyphenation()
{
return $this->autoHyphenation;
}
/**
* @param bool $autoHyphenation
*/
public function setAutoHyphenation($autoHyphenation)
{
$this->autoHyphenation = (bool) $autoHyphenation;
}
/**
* @return int|null
*/
public function getConsecutiveHyphenLimit()
{
return $this->consecutiveHyphenLimit;
}
/**
* @param int $consecutiveHyphenLimit
*/
public function setConsecutiveHyphenLimit($consecutiveHyphenLimit)
{
$this->consecutiveHyphenLimit = (int) $consecutiveHyphenLimit;
}
/**
* @return float|null
*/
public function getHyphenationZone()
{
return $this->hyphenationZone;
}
/**
* @param float $hyphenationZone Measurement unit is twip
*/
public function setHyphenationZone($hyphenationZone)
{
$this->hyphenationZone = $hyphenationZone;
}
/**
* @return null|bool
*/
public function hasDoNotHyphenateCaps()
{
return $this->doNotHyphenateCaps;
}
/**
* @param bool $doNotHyphenateCaps
*/
public function setDoNotHyphenateCaps($doNotHyphenateCaps)
{
$this->doNotHyphenateCaps = (bool) $doNotHyphenateCaps;
}
}

View File

@@ -0,0 +1,425 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord;
use PhpOffice\PhpWord\Element\Section;
use PhpOffice\PhpWord\Exception\Exception;
/**
* PHPWord main class
*
* @method Collection\Titles getTitles()
* @method Collection\Footnotes getFootnotes()
* @method Collection\Endnotes getEndnotes()
* @method Collection\Charts getCharts()
* @method Collection\Comments getComments()
* @method int addBookmark(Element\Bookmark $bookmark)
* @method int addTitle(Element\Title $title)
* @method int addFootnote(Element\Footnote $footnote)
* @method int addEndnote(Element\Endnote $endnote)
* @method int addChart(Element\Chart $chart)
* @method int addComment(Element\Comment $comment)
*
* @method Style\Paragraph addParagraphStyle(string $styleName, mixed $styles)
* @method Style\Font addFontStyle(string $styleName, mixed $fontStyle, mixed $paragraphStyle = null)
* @method Style\Font addLinkStyle(string $styleName, mixed $styles)
* @method Style\Font addTitleStyle(mixed $depth, mixed $fontStyle, mixed $paragraphStyle = null)
* @method Style\Table addTableStyle(string $styleName, mixed $styleTable, mixed $styleFirstRow = null)
* @method Style\Numbering addNumberingStyle(string $styleName, mixed $styles)
*/
class PhpWord
{
/**
* Default font settings
*
* @deprecated 0.11.0 Use Settings constants
*
* @const string|int
*/
const DEFAULT_FONT_NAME = Settings::DEFAULT_FONT_NAME;
/**
* @deprecated 0.11.0 Use Settings constants
*/
const DEFAULT_FONT_SIZE = Settings::DEFAULT_FONT_SIZE;
/**
* @deprecated 0.11.0 Use Settings constants
*/
const DEFAULT_FONT_COLOR = Settings::DEFAULT_FONT_COLOR;
/**
* @deprecated 0.11.0 Use Settings constants
*/
const DEFAULT_FONT_CONTENT_TYPE = Settings::DEFAULT_FONT_CONTENT_TYPE;
/**
* Collection of sections
*
* @var \PhpOffice\PhpWord\Element\Section[]
*/
private $sections = array();
/**
* Collections
*
* @var array
*/
private $collections = array();
/**
* Metadata
*
* @var array
* @since 0.12.0
*/
private $metadata = array();
/**
* Create new instance
*
* Collections are created dynamically
*/
public function __construct()
{
// Reset Media and styles
Media::resetElements();
Style::resetStyles();
// Collection
$collections = array('Bookmarks', 'Titles', 'Footnotes', 'Endnotes', 'Charts', 'Comments');
foreach ($collections as $collection) {
$class = 'PhpOffice\\PhpWord\\Collection\\' . $collection;
$this->collections[$collection] = new $class();
}
// Metadata
$metadata = array('DocInfo', 'Settings', 'Compatibility');
foreach ($metadata as $meta) {
$class = 'PhpOffice\\PhpWord\\Metadata\\' . $meta;
$this->metadata[$meta] = new $class();
}
}
/**
* Dynamic function call to reduce static dependency
*
* @since 0.12.0
*
* @param mixed $function
* @param mixed $args
*
* @throws \BadMethodCallException
*
* @return mixed
*/
public function __call($function, $args)
{
$function = strtolower($function);
$getCollection = array();
$addCollection = array();
$addStyle = array();
$collections = array('Bookmark', 'Title', 'Footnote', 'Endnote', 'Chart', 'Comment');
foreach ($collections as $collection) {
$getCollection[] = strtolower("get{$collection}s");
$addCollection[] = strtolower("add{$collection}");
}
$styles = array('Paragraph', 'Font', 'Table', 'Numbering', 'Link', 'Title');
foreach ($styles as $style) {
$addStyle[] = strtolower("add{$style}Style");
}
// Run get collection method
if (in_array($function, $getCollection)) {
$key = ucfirst(str_replace('get', '', $function));
return $this->collections[$key];
}
// Run add collection item method
if (in_array($function, $addCollection)) {
$key = ucfirst(str_replace('add', '', $function) . 's');
/** @var \PhpOffice\PhpWord\Collection\AbstractCollection $collectionObject */
$collectionObject = $this->collections[$key];
return $collectionObject->addItem(isset($args[0]) ? $args[0] : null);
}
// Run add style method
if (in_array($function, $addStyle)) {
return forward_static_call_array(array('PhpOffice\\PhpWord\\Style', $function), $args);
}
// Exception
throw new \BadMethodCallException("Method $function is not defined.");
}
/**
* Get document properties object
*
* @return \PhpOffice\PhpWord\Metadata\DocInfo
*/
public function getDocInfo()
{
return $this->metadata['DocInfo'];
}
/**
* Get protection
*
* @return \PhpOffice\PhpWord\Metadata\Protection
* @since 0.12.0
* @deprecated Get the Document protection from PhpWord->getSettings()->getDocumentProtection();
* @codeCoverageIgnore
*/
public function getProtection()
{
return $this->getSettings()->getDocumentProtection();
}
/**
* Get compatibility
*
* @return \PhpOffice\PhpWord\Metadata\Compatibility
* @since 0.12.0
*/
public function getCompatibility()
{
return $this->metadata['Compatibility'];
}
/**
* Get compatibility
*
* @return \PhpOffice\PhpWord\Metadata\Settings
* @since 0.14.0
*/
public function getSettings()
{
return $this->metadata['Settings'];
}
/**
* Get all sections
*
* @return \PhpOffice\PhpWord\Element\Section[]
*/
public function getSections()
{
return $this->sections;
}
/**
* Returns the section at the requested position
*
* @param int $index
* @return \PhpOffice\PhpWord\Element\Section|null
*/
public function getSection($index)
{
if (array_key_exists($index, $this->sections)) {
return $this->sections[$index];
}
return null;
}
/**
* Create new section
*
* @param array $style
* @return \PhpOffice\PhpWord\Element\Section
*/
public function addSection($style = null)
{
$section = new Section(count($this->sections) + 1, $style);
$section->setPhpWord($this);
$this->sections[] = $section;
return $section;
}
/**
* Sorts the sections using the callable passed
*
* @see http://php.net/manual/en/function.usort.php for usage
* @param callable $sorter
*/
public function sortSections($sorter)
{
usort($this->sections, $sorter);
}
/**
* Get default font name
*
* @return string
*/
public function getDefaultFontName()
{
return Settings::getDefaultFontName();
}
/**
* Set default font name.
*
* @param string $fontName
*/
public function setDefaultFontName($fontName)
{
Settings::setDefaultFontName($fontName);
}
/**
* Get default font size
*
* @return int
*/
public function getDefaultFontSize()
{
return Settings::getDefaultFontSize();
}
/**
* Set default font size.
*
* @param int $fontSize
*/
public function setDefaultFontSize($fontSize)
{
Settings::setDefaultFontSize($fontSize);
}
/**
* Set default paragraph style definition to styles.xml
*
* @param array $styles Paragraph style definition
* @return \PhpOffice\PhpWord\Style\Paragraph
*/
public function setDefaultParagraphStyle($styles)
{
return Style::setDefaultParagraphStyle($styles);
}
/**
* Load template by filename
*
* @deprecated 0.12.0 Use `new TemplateProcessor($documentTemplate)` instead.
*
* @param string $filename Fully qualified filename
*
* @throws \PhpOffice\PhpWord\Exception\Exception
*
* @return TemplateProcessor
*
* @codeCoverageIgnore
*/
public function loadTemplate($filename)
{
if (file_exists($filename)) {
return new TemplateProcessor($filename);
}
throw new Exception("Template file {$filename} not found.");
}
/**
* Save to file or download
*
* All exceptions should already been handled by the writers
*
* @param string $filename
* @param string $format
* @param bool $download
* @return bool
*/
public function save($filename, $format = 'Word2007', $download = false)
{
$mime = array(
'Word2007' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'ODText' => 'application/vnd.oasis.opendocument.text',
'RTF' => 'application/rtf',
'HTML' => 'text/html',
'PDF' => 'application/pdf',
);
$writer = IOFactory::createWriter($this, $format);
if ($download === true) {
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Content-Type: ' . $mime[$format]);
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Expires: 0');
$filename = 'php://output'; // Change filename to force download
}
$writer->save($filename);
return true;
}
/**
* Create new section
*
* @deprecated 0.10.0
*
* @param array $settings
*
* @return \PhpOffice\PhpWord\Element\Section
*
* @codeCoverageIgnore
*/
public function createSection($settings = null)
{
return $this->addSection($settings);
}
/**
* Get document properties object
*
* @deprecated 0.12.0
*
* @return \PhpOffice\PhpWord\Metadata\DocInfo
*
* @codeCoverageIgnore
*/
public function getDocumentProperties()
{
return $this->getDocInfo();
}
/**
* Set document properties object
*
* @deprecated 0.12.0
*
* @param \PhpOffice\PhpWord\Metadata\DocInfo $documentProperties
*
* @return self
*
* @codeCoverageIgnore
*/
public function setDocumentProperties($documentProperties)
{
$this->metadata['Document'] = $documentProperties;
return $this;
}
}

View File

@@ -0,0 +1,124 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Reader;
use PhpOffice\PhpWord\Exception\Exception;
/**
* Reader abstract class
*
* @since 0.8.0
*
* @codeCoverageIgnore Abstract class
*/
abstract class AbstractReader implements ReaderInterface
{
/**
* Read data only?
*
* @var bool
*/
protected $readDataOnly = true;
/**
* File pointer
*
* @var bool|resource
*/
protected $fileHandle;
/**
* Read data only?
*
* @return bool
*/
public function isReadDataOnly()
{
// return $this->readDataOnly;
return true;
}
/**
* Set read data only
*
* @param bool $value
* @return self
*/
public function setReadDataOnly($value = true)
{
$this->readDataOnly = $value;
return $this;
}
/**
* Open file for reading
*
* @param string $filename
*
* @throws \PhpOffice\PhpWord\Exception\Exception
*
* @return resource
*/
protected function openFile($filename)
{
// Check if file exists
if (!file_exists($filename) || !is_readable($filename)) {
throw new Exception("Could not open $filename for reading! File does not exist.");
}
// Open file
$this->fileHandle = fopen($filename, 'r');
if ($this->fileHandle === false) {
throw new Exception("Could not open file $filename for reading.");
}
}
/**
* Can the current ReaderInterface read the file?
*
* @param string $filename
* @return bool
*/
public function canRead($filename)
{
// Check if file exists
try {
$this->openFile($filename);
} catch (Exception $e) {
return false;
}
if (is_resource($this->fileHandle)) {
fclose($this->fileHandle);
}
return true;
}
/**
* Read data only?
*
* @deprecated 0.10.0
*
* @codeCoverageIgnore
*/
public function getReadDataOnly()
{
return $this->isReadDataOnly();
}
}

View File

@@ -0,0 +1,52 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Reader;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\Html as HTMLParser;
/**
* HTML Reader class
*
* @since 0.11.0
*/
class HTML extends AbstractReader implements ReaderInterface
{
/**
* Loads PhpWord from file
*
* @param string $docFile
*
* @throws \Exception
*
* @return \PhpOffice\PhpWord\PhpWord
*/
public function load($docFile)
{
$phpWord = new PhpWord();
if ($this->canRead($docFile)) {
$section = $phpWord->addSection();
HTMLParser::addHtml($section, file_get_contents($docFile), true);
} else {
throw new \Exception("Cannot read {$docFile}.");
}
return $phpWord;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,94 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Reader;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLReader;
/**
* Reader for ODText
*
* @since 0.10.0
*/
class ODText extends AbstractReader implements ReaderInterface
{
/**
* Loads PhpWord from file
*
* @param string $docFile
* @return \PhpOffice\PhpWord\PhpWord
*/
public function load($docFile)
{
$phpWord = new PhpWord();
$relationships = $this->readRelationships($docFile);
$readerParts = array(
'content.xml' => 'Content',
'meta.xml' => 'Meta',
);
foreach ($readerParts as $xmlFile => $partName) {
$this->readPart($phpWord, $relationships, $partName, $docFile, $xmlFile);
}
return $phpWord;
}
/**
* Read document part.
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
* @param array $relationships
* @param string $partName
* @param string $docFile
* @param string $xmlFile
*/
private function readPart(PhpWord $phpWord, $relationships, $partName, $docFile, $xmlFile)
{
$partClass = "PhpOffice\\PhpWord\\Reader\\ODText\\{$partName}";
if (class_exists($partClass)) {
/** @var \PhpOffice\PhpWord\Reader\ODText\AbstractPart $part Type hint */
$part = new $partClass($docFile, $xmlFile);
$part->setRels($relationships);
$part->read($phpWord);
}
}
/**
* Read all relationship files
*
* @param string $docFile
* @return array
*/
private function readRelationships($docFile)
{
$rels = array();
$xmlFile = 'META-INF/manifest.xml';
$xmlReader = new XMLReader();
$xmlReader->getDomFromZip($docFile, $xmlFile);
$nodes = $xmlReader->getElements('manifest:file-entry');
foreach ($nodes as $node) {
$type = $xmlReader->getAttribute('manifest:media-type', $node);
$target = $xmlReader->getAttribute('manifest:full-path', $node);
$rels[] = array('type' => $type, 'target' => $target);
}
return $rels;
}
}

View File

@@ -0,0 +1,30 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Reader\ODText;
use PhpOffice\PhpWord\Reader\Word2007\AbstractPart as Word2007AbstractPart;
/**
* Abstract part reader
*
* @since 0.10.0
* @codeCoverageIgnore
*/
abstract class AbstractPart extends Word2007AbstractPart
{
}

View File

@@ -0,0 +1,112 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Reader\ODText;
use PhpOffice\PhpWord\Element\TrackChange;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLReader;
/**
* Content reader
*
* @since 0.10.0
*/
class Content extends AbstractPart
{
/**
* Read content.xml.
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
*/
public function read(PhpWord $phpWord)
{
$xmlReader = new XMLReader();
$xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
$trackedChanges = array();
$nodes = $xmlReader->getElements('office:body/office:text/*');
if ($nodes->length > 0) {
$section = $phpWord->addSection();
foreach ($nodes as $node) {
// $styleName = $xmlReader->getAttribute('text:style-name', $node);
switch ($node->nodeName) {
case 'text:h': // Heading
$depth = $xmlReader->getAttribute('text:outline-level', $node);
$section->addTitle($node->nodeValue, $depth);
break;
case 'text:p': // Paragraph
$children = $node->childNodes;
foreach ($children as $child) {
switch ($child->nodeName) {
case 'text:change-start':
$changeId = $child->getAttribute('text:change-id');
if (isset($trackedChanges[$changeId])) {
$changed = $trackedChanges[$changeId];
}
break;
case 'text:change-end':
unset($changed);
break;
case 'text:change':
$changeId = $child->getAttribute('text:change-id');
if (isset($trackedChanges[$changeId])) {
$changed = $trackedChanges[$changeId];
}
break;
}
}
$element = $section->addText($node->nodeValue);
if (isset($changed) && is_array($changed)) {
$element->setTrackChange($changed['changed']);
if (isset($changed['textNodes'])) {
foreach ($changed['textNodes'] as $changedNode) {
$element = $section->addText($changedNode->nodeValue);
$element->setTrackChange($changed['changed']);
}
}
}
break;
case 'text:list': // List
$listItems = $xmlReader->getElements('text:list-item/text:p', $node);
foreach ($listItems as $listItem) {
// $listStyleName = $xmlReader->getAttribute('text:style-name', $listItem);
$section->addListItem($listItem->nodeValue, 0);
}
break;
case 'text:tracked-changes':
$changedRegions = $xmlReader->getElements('text:changed-region', $node);
foreach ($changedRegions as $changedRegion) {
$type = ($changedRegion->firstChild->nodeName == 'text:insertion') ? TrackChange::INSERTED : TrackChange::DELETED;
$creatorNode = $xmlReader->getElements('office:change-info/dc:creator', $changedRegion->firstChild);
$author = $creatorNode[0]->nodeValue;
$dateNode = $xmlReader->getElements('office:change-info/dc:date', $changedRegion->firstChild);
$date = $dateNode[0]->nodeValue;
$date = preg_replace('/\.\d+$/', '', $date);
$date = \DateTime::createFromFormat('Y-m-d\TH:i:s', $date);
$changed = new TrackChange($type, $author, $date);
$textNodes = $xmlReader->getElements('text:deletion/text:p', $changedRegion);
$trackedChanges[$changedRegion->getAttribute('text:id')] = array('changed' => $changed, 'textNodes'=> $textNodes);
}
break;
}
}
}
}
}

View File

@@ -0,0 +1,78 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Reader\ODText;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLReader;
/**
* Meta reader
*
* @since 0.11.0
*/
class Meta extends AbstractPart
{
/**
* Read meta.xml.
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
* @todo Process property type
*/
public function read(PhpWord $phpWord)
{
$xmlReader = new XMLReader();
$xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
$docProps = $phpWord->getDocInfo();
$metaNode = $xmlReader->getElement('office:meta');
// Standard properties
$properties = array(
'title' => 'dc:title',
'subject' => 'dc:subject',
'description' => 'dc:description',
'keywords' => 'meta:keyword',
'creator' => 'meta:initial-creator',
'lastModifiedBy' => 'dc:creator',
// 'created' => 'meta:creation-date',
// 'modified' => 'dc:date',
);
foreach ($properties as $property => $path) {
$method = "set{$property}";
$propertyNode = $xmlReader->getElement($path, $metaNode);
if ($propertyNode !== null && method_exists($docProps, $method)) {
$docProps->$method($propertyNode->nodeValue);
}
}
// Custom properties
$propertyNodes = $xmlReader->getElements('meta:user-defined', $metaNode);
foreach ($propertyNodes as $propertyNode) {
$property = $xmlReader->getAttribute('meta:name', $propertyNode);
// Set category, company, and manager property
if (in_array($property, array('Category', 'Company', 'Manager'))) {
$method = "set{$property}";
$docProps->$method($propertyNode->nodeValue);
} else {
// Set other custom properties
$docProps->setCustomProperty($property, $propertyNode->nodeValue);
}
}
}
}

View File

@@ -0,0 +1,53 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Reader;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Reader\RTF\Document;
/**
* RTF Reader class
*
* @since 0.11.0
*/
class RTF extends AbstractReader implements ReaderInterface
{
/**
* Loads PhpWord from file
*
* @param string $docFile
*
* @throws \Exception
*
* @return \PhpOffice\PhpWord\PhpWord
*/
public function load($docFile)
{
$phpWord = new PhpWord();
if ($this->canRead($docFile)) {
$doc = new Document();
$doc->rtf = file_get_contents($docFile);
$doc->read($phpWord);
} else {
throw new \Exception("Cannot read {$docFile}.");
}
return $phpWord;
}
}

View File

@@ -0,0 +1,394 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Reader\RTF;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\SimpleType\Jc;
/**
* RTF document reader
*
* References:
* - How to Write an RTF Reader http://latex2rtf.sourceforge.net/rtfspec_45.html
* - PHP rtfclass by Markus Fischer https://github.com/mfn/rtfclass
* - JavaScript RTF-parser by LazyGyu https://github.com/lazygyu/RTF-parser
*
* @since 0.11.0
* @SuppressWarnings(PHPMD.UnusedPrivateMethod)
*/
class Document
{
/** @const int */
const PARA = 'readParagraph';
const STYL = 'readStyle';
const SKIP = 'readSkip';
/**
* PhpWord object
*
* @var \PhpOffice\PhpWord\PhpWord
*/
private $phpWord;
/**
* Section object
*
* @var \PhpOffice\PhpWord\Element\Section
*/
private $section;
/**
* Textrun object
*
* @var \PhpOffice\PhpWord\Element\TextRun
*/
private $textrun;
/**
* RTF content
*
* @var string
*/
public $rtf;
/**
* Content length
*
* @var int
*/
private $length = 0;
/**
* Character index
*
* @var int
*/
private $offset = 0;
/**
* Current control word
*
* @var string
*/
private $control = '';
/**
* Text content
*
* @var string
*/
private $text = '';
/**
* Parsing a control word flag
*
* @var bool
*/
private $isControl = false;
/**
* First character flag: watch out for control symbols
*
* @var bool
*/
private $isFirst = false;
/**
* Group groups
*
* @var array
*/
private $groups = array();
/**
* Parser flags; not used
*
* @var array
*/
private $flags = array();
/**
* Parse RTF content
*
* - Marks controlling characters `{`, `}`, and `\`
* - Removes line endings
* - Builds control words and control symbols
* - Pushes every other character into the text queue
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
* @todo Use `fread` stream for scalability
*/
public function read(PhpWord $phpWord)
{
$markers = array(
123 => 'markOpening', // {
125 => 'markClosing', // }
92 => 'markBackslash', // \
10 => 'markNewline', // LF
13 => 'markNewline', // CR
);
$this->phpWord = $phpWord;
$this->section = $phpWord->addSection();
$this->textrun = $this->section->addTextRun();
$this->length = strlen($this->rtf);
$this->flags['paragraph'] = true; // Set paragraph flag from the beginning
// Walk each characters
while ($this->offset < $this->length) {
$char = $this->rtf[$this->offset];
$ascii = ord($char);
if (isset($markers[$ascii])) { // Marker found: {, }, \, LF, or CR
$markerFunction = $markers[$ascii];
$this->$markerFunction();
} else {
if (false === $this->isControl) { // Non control word: Push character
$this->pushText($char);
} else {
if (preg_match('/^[a-zA-Z0-9-]?$/', $char)) { // No delimiter: Buffer control
$this->control .= $char;
$this->isFirst = false;
} else { // Delimiter found: Parse buffered control
if ($this->isFirst) {
$this->isFirst = false;
} else {
if (' ' == $char) { // Discard space as a control word delimiter
$this->flushControl(true);
}
}
}
}
}
$this->offset++;
}
$this->flushText();
}
/**
* Mark opening braket `{` character.
*/
private function markOpening()
{
$this->flush(true);
array_push($this->groups, $this->flags);
}
/**
* Mark closing braket `}` character.
*/
private function markClosing()
{
$this->flush(true);
$this->flags = array_pop($this->groups);
}
/**
* Mark backslash `\` character.
*/
private function markBackslash()
{
if ($this->isFirst) {
$this->setControl(false);
$this->text .= '\\';
} else {
$this->flush();
$this->setControl(true);
$this->control = '';
}
}
/**
* Mark newline character: Flush control word because it's not possible to span multiline.
*/
private function markNewline()
{
if ($this->isControl) {
$this->flushControl(true);
}
}
/**
* Flush control word or text.
*
* @param bool $isControl
*/
private function flush($isControl = false)
{
if ($this->isControl) {
$this->flushControl($isControl);
} else {
$this->flushText();
}
}
/**
* Flush control word.
*
* @param bool $isControl
*/
private function flushControl($isControl = false)
{
if (1 === preg_match('/^([A-Za-z]+)(-?[0-9]*) ?$/', $this->control, $match)) {
list(, $control, $parameter) = $match;
$this->parseControl($control, $parameter);
}
if (true === $isControl) {
$this->setControl(false);
}
}
/**
* Flush text in queue.
*/
private function flushText()
{
if ($this->text != '') {
if (isset($this->flags['property'])) { // Set property
$this->flags['value'] = $this->text;
} else { // Set text
if (true === $this->flags['paragraph']) {
$this->flags['paragraph'] = false;
$this->flags['text'] = $this->text;
}
}
// Add text if it's not flagged as skipped
if (!isset($this->flags['skipped'])) {
$this->readText();
}
$this->text = '';
}
}
/**
* Reset control word and first char state.
*
* @param bool $value
*/
private function setControl($value)
{
$this->isControl = $value;
$this->isFirst = $value;
}
/**
* Push text into queue.
*
* @param string $char
*/
private function pushText($char)
{
if ('<' == $char) {
$this->text .= '&lt;';
} elseif ('>' == $char) {
$this->text .= '&gt;';
} else {
$this->text .= $char;
}
}
/**
* Parse control.
*
* @param string $control
* @param string $parameter
*/
private function parseControl($control, $parameter)
{
$controls = array(
'par' => array(self::PARA, 'paragraph', true),
'b' => array(self::STYL, 'font', 'bold', true),
'i' => array(self::STYL, 'font', 'italic', true),
'u' => array(self::STYL, 'font', 'underline', true),
'strike' => array(self::STYL, 'font', 'strikethrough', true),
'fs' => array(self::STYL, 'font', 'size', $parameter),
'qc' => array(self::STYL, 'paragraph', 'alignment', Jc::CENTER),
'sa' => array(self::STYL, 'paragraph', 'spaceAfter', $parameter),
'fonttbl' => array(self::SKIP, 'fonttbl', null),
'colortbl' => array(self::SKIP, 'colortbl', null),
'info' => array(self::SKIP, 'info', null),
'generator' => array(self::SKIP, 'generator', null),
'title' => array(self::SKIP, 'title', null),
'subject' => array(self::SKIP, 'subject', null),
'category' => array(self::SKIP, 'category', null),
'keywords' => array(self::SKIP, 'keywords', null),
'comment' => array(self::SKIP, 'comment', null),
'shppict' => array(self::SKIP, 'pic', null),
'fldinst' => array(self::SKIP, 'link', null),
);
if (isset($controls[$control])) {
list($function) = $controls[$control];
if (method_exists($this, $function)) {
$directives = $controls[$control];
array_shift($directives); // remove the function variable; we won't need it
$this->$function($directives);
}
}
}
/**
* Read paragraph.
*
* @param array $directives
*/
private function readParagraph($directives)
{
list($property, $value) = $directives;
$this->textrun = $this->section->addTextRun();
$this->flags[$property] = $value;
}
/**
* Read style.
*
* @param array $directives
*/
private function readStyle($directives)
{
list($style, $property, $value) = $directives;
$this->flags['styles'][$style][$property] = $value;
}
/**
* Read skip.
*
* @param array $directives
*/
private function readSkip($directives)
{
list($property) = $directives;
$this->flags['property'] = $property;
$this->flags['skipped'] = true;
}
/**
* Read text.
*/
private function readText()
{
$text = $this->textrun->addText($this->text);
if (isset($this->flags['styles']['font'])) {
$text->getFontStyle()->setStyleByArray($this->flags['styles']['font']);
}
}
}

View File

@@ -0,0 +1,41 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Reader;
/**
* Reader interface
*
* @since 0.8.0
*/
interface ReaderInterface
{
/**
* Can the current ReaderInterface read the file?
*
* @param string $filename
* @return bool
*/
public function canRead($filename);
/**
* Loads PhpWord from file
*
* @param string $filename
*/
public function load($filename);
}

View File

@@ -0,0 +1,172 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Reader;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLReader;
use PhpOffice\PhpWord\Shared\ZipArchive;
/**
* Reader for Word2007
*
* @since 0.8.0
* @todo watermark, checkbox, toc
* @todo Partly done: image, object
*/
class Word2007 extends AbstractReader implements ReaderInterface
{
/**
* Loads PhpWord from file
*
* @param string $docFile
* @return \PhpOffice\PhpWord\PhpWord
*/
public function load($docFile)
{
$phpWord = new PhpWord();
$relationships = $this->readRelationships($docFile);
$steps = array(
array('stepPart' => 'document', 'stepItems' => array(
'styles' => 'Styles',
'numbering' => 'Numbering',
)),
array('stepPart' => 'main', 'stepItems' => array(
'officeDocument' => 'Document',
'core-properties' => 'DocPropsCore',
'extended-properties' => 'DocPropsApp',
'custom-properties' => 'DocPropsCustom',
)),
array('stepPart' => 'document', 'stepItems' => array(
'endnotes' => 'Endnotes',
'footnotes' => 'Footnotes',
'settings' => 'Settings',
)),
);
foreach ($steps as $step) {
$stepPart = $step['stepPart'];
$stepItems = $step['stepItems'];
if (!isset($relationships[$stepPart])) {
continue;
}
foreach ($relationships[$stepPart] as $relItem) {
$relType = $relItem['type'];
if (isset($stepItems[$relType])) {
$partName = $stepItems[$relType];
$xmlFile = $relItem['target'];
$this->readPart($phpWord, $relationships, $partName, $docFile, $xmlFile);
}
}
}
return $phpWord;
}
/**
* Read document part.
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
* @param array $relationships
* @param string $partName
* @param string $docFile
* @param string $xmlFile
*/
private function readPart(PhpWord $phpWord, $relationships, $partName, $docFile, $xmlFile)
{
$partClass = "PhpOffice\\PhpWord\\Reader\\Word2007\\{$partName}";
if (class_exists($partClass)) {
/** @var \PhpOffice\PhpWord\Reader\Word2007\AbstractPart $part Type hint */
$part = new $partClass($docFile, $xmlFile);
$part->setRels($relationships);
$part->read($phpWord);
}
}
/**
* Read all relationship files
*
* @param string $docFile
* @return array
*/
private function readRelationships($docFile)
{
$relationships = array();
// _rels/.rels
$relationships['main'] = $this->getRels($docFile, '_rels/.rels');
// word/_rels/*.xml.rels
$wordRelsPath = 'word/_rels/';
$zip = new ZipArchive();
if ($zip->open($docFile) === true) {
for ($i = 0; $i < $zip->numFiles; $i++) {
$xmlFile = $zip->getNameIndex($i);
if ((substr($xmlFile, 0, strlen($wordRelsPath))) == $wordRelsPath && (substr($xmlFile, -1)) != '/') {
$docPart = str_replace('.xml.rels', '', str_replace($wordRelsPath, '', $xmlFile));
$relationships[$docPart] = $this->getRels($docFile, $xmlFile, 'word/');
}
}
$zip->close();
}
return $relationships;
}
/**
* Get relationship array
*
* @param string $docFile
* @param string $xmlFile
* @param string $targetPrefix
* @return array
*/
private function getRels($docFile, $xmlFile, $targetPrefix = '')
{
$metaPrefix = 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/';
$officePrefix = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/';
$rels = array();
$xmlReader = new XMLReader();
$xmlReader->getDomFromZip($docFile, $xmlFile);
$nodes = $xmlReader->getElements('*');
foreach ($nodes as $node) {
$rId = $xmlReader->getAttribute('Id', $node);
$type = $xmlReader->getAttribute('Type', $node);
$target = $xmlReader->getAttribute('Target', $node);
$mode = $xmlReader->getAttribute('TargetMode', $node);
// Remove URL prefixes from $type to make it easier to read
$type = str_replace($metaPrefix, '', $type);
$type = str_replace($officePrefix, '', $type);
$docPart = str_replace('.xml', '', $target);
// Do not add prefix to link source
if ($type != 'hyperlink' && $mode != 'External') {
$target = $targetPrefix . $target;
}
// Push to return array
$rels[$rId] = array('type' => $type, 'target' => $target, 'docPart' => $docPart, 'targetMode' => $mode);
}
ksort($rels);
return $rels;
}
}

View File

@@ -0,0 +1,746 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Reader\Word2007;
use PhpOffice\PhpWord\ComplexType\TblWidth as TblWidthComplexType;
use PhpOffice\PhpWord\Element\AbstractContainer;
use PhpOffice\PhpWord\Element\TextRun;
use PhpOffice\PhpWord\Element\TrackChange;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLReader;
/**
* Abstract part reader
*
* This class is inherited by ODText reader
*
* @since 0.10.0
*/
abstract class AbstractPart
{
/**
* Conversion method
*
* @const int
*/
const READ_VALUE = 'attributeValue'; // Read attribute value
const READ_EQUAL = 'attributeEquals'; // Read `true` when attribute value equals specified value
const READ_TRUE = 'attributeTrue'; // Read `true` when element exists
const READ_FALSE = 'attributeFalse'; // Read `false` when element exists
const READ_SIZE = 'attributeMultiplyByTwo'; // Read special attribute value for Font::$size
/**
* Document file
*
* @var string
*/
protected $docFile;
/**
* XML file
*
* @var string
*/
protected $xmlFile;
/**
* Part relationships
*
* @var array
*/
protected $rels = array();
/**
* Read part.
*/
abstract public function read(PhpWord $phpWord);
/**
* Create new instance
*
* @param string $docFile
* @param string $xmlFile
*/
public function __construct($docFile, $xmlFile)
{
$this->docFile = $docFile;
$this->xmlFile = $xmlFile;
}
/**
* Set relationships.
*
* @param array $value
*/
public function setRels($value)
{
$this->rels = $value;
}
/**
* Read w:p.
*
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode
* @param \PhpOffice\PhpWord\Element\AbstractContainer $parent
* @param string $docPart
*
* @todo Get font style for preserve text
*/
protected function readParagraph(XMLReader $xmlReader, \DOMElement $domNode, $parent, $docPart = 'document')
{
// Paragraph style
$paragraphStyle = null;
$headingDepth = null;
if ($xmlReader->elementExists('w:pPr', $domNode)) {
$paragraphStyle = $this->readParagraphStyle($xmlReader, $domNode);
$headingDepth = $this->getHeadingDepth($paragraphStyle);
}
// PreserveText
if ($xmlReader->elementExists('w:r/w:instrText', $domNode)) {
$ignoreText = false;
$textContent = '';
$fontStyle = $this->readFontStyle($xmlReader, $domNode);
$nodes = $xmlReader->getElements('w:r', $domNode);
foreach ($nodes as $node) {
$instrText = $xmlReader->getValue('w:instrText', $node);
if ($xmlReader->elementExists('w:fldChar', $node)) {
$fldCharType = $xmlReader->getAttribute('w:fldCharType', $node, 'w:fldChar');
if ('begin' == $fldCharType) {
$ignoreText = true;
} elseif ('end' == $fldCharType) {
$ignoreText = false;
}
}
if (!is_null($instrText)) {
$textContent .= '{' . $instrText . '}';
} else {
if (false === $ignoreText) {
$textContent .= $xmlReader->getValue('w:t', $node);
}
}
}
$parent->addPreserveText(htmlspecialchars($textContent, ENT_QUOTES, 'UTF-8'), $fontStyle, $paragraphStyle);
} elseif ($xmlReader->elementExists('w:pPr/w:numPr', $domNode)) {
// List item
$numId = $xmlReader->getAttribute('w:val', $domNode, 'w:pPr/w:numPr/w:numId');
$levelId = $xmlReader->getAttribute('w:val', $domNode, 'w:pPr/w:numPr/w:ilvl');
$nodes = $xmlReader->getElements('*', $domNode);
$listItemRun = $parent->addListItemRun($levelId, "PHPWordList{$numId}", $paragraphStyle);
foreach ($nodes as $node) {
$this->readRun($xmlReader, $node, $listItemRun, $docPart, $paragraphStyle);
}
} elseif ($headingDepth !== null) {
// Heading or Title
$textContent = null;
$nodes = $xmlReader->getElements('w:r', $domNode);
if ($nodes->length === 1) {
$textContent = htmlspecialchars($xmlReader->getValue('w:t', $nodes->item(0)), ENT_QUOTES, 'UTF-8');
} else {
$textContent = new TextRun($paragraphStyle);
foreach ($nodes as $node) {
$this->readRun($xmlReader, $node, $textContent, $docPart, $paragraphStyle);
}
}
$parent->addTitle($textContent, $headingDepth);
} else {
// Text and TextRun
$textRunContainers = $xmlReader->countElements('w:r|w:ins|w:del|w:hyperlink|w:smartTag', $domNode);
if (0 === $textRunContainers) {
$parent->addTextBreak(null, $paragraphStyle);
} else {
$nodes = $xmlReader->getElements('*', $domNode);
$paragraph = $parent->addTextRun($paragraphStyle);
foreach ($nodes as $node) {
$this->readRun($xmlReader, $node, $paragraph, $docPart, $paragraphStyle);
}
}
}
}
/**
* Returns the depth of the Heading, returns 0 for a Title
*
* @param array $paragraphStyle
* @return number|null
*/
private function getHeadingDepth(array $paragraphStyle = null)
{
if (is_array($paragraphStyle) && isset($paragraphStyle['styleName'])) {
if ('Title' === $paragraphStyle['styleName']) {
return 0;
}
$headingMatches = array();
preg_match('/Heading(\d)/', $paragraphStyle['styleName'], $headingMatches);
if (!empty($headingMatches)) {
return $headingMatches[1];
}
}
return null;
}
/**
* Read w:r.
*
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode
* @param \PhpOffice\PhpWord\Element\AbstractContainer $parent
* @param string $docPart
* @param mixed $paragraphStyle
*
* @todo Footnote paragraph style
*/
protected function readRun(XMLReader $xmlReader, \DOMElement $domNode, $parent, $docPart, $paragraphStyle = null)
{
if (in_array($domNode->nodeName, array('w:ins', 'w:del', 'w:smartTag', 'w:hyperlink'))) {
$nodes = $xmlReader->getElements('*', $domNode);
foreach ($nodes as $node) {
$this->readRun($xmlReader, $node, $parent, $docPart, $paragraphStyle);
}
} elseif ($domNode->nodeName == 'w:r') {
$fontStyle = $this->readFontStyle($xmlReader, $domNode);
$nodes = $xmlReader->getElements('*', $domNode);
foreach ($nodes as $node) {
$this->readRunChild($xmlReader, $node, $parent, $docPart, $paragraphStyle, $fontStyle);
}
}
}
/**
* Parses nodes under w:r
*
* @param XMLReader $xmlReader
* @param \DOMElement $node
* @param AbstractContainer $parent
* @param string $docPart
* @param mixed $paragraphStyle
* @param mixed $fontStyle
*/
protected function readRunChild(XMLReader $xmlReader, \DOMElement $node, AbstractContainer $parent, $docPart, $paragraphStyle = null, $fontStyle = null)
{
$runParent = $node->parentNode->parentNode;
if ($node->nodeName == 'w:footnoteReference') {
// Footnote
$wId = $xmlReader->getAttribute('w:id', $node);
$footnote = $parent->addFootnote();
$footnote->setRelationId($wId);
} elseif ($node->nodeName == 'w:endnoteReference') {
// Endnote
$wId = $xmlReader->getAttribute('w:id', $node);
$endnote = $parent->addEndnote();
$endnote->setRelationId($wId);
} elseif ($node->nodeName == 'w:pict') {
// Image
$rId = $xmlReader->getAttribute('r:id', $node, 'v:shape/v:imagedata');
$target = $this->getMediaTarget($docPart, $rId);
if (!is_null($target)) {
if ('External' == $this->getTargetMode($docPart, $rId)) {
$imageSource = $target;
} else {
$imageSource = "zip://{$this->docFile}#{$target}";
}
$parent->addImage($imageSource);
}
} elseif ($node->nodeName == 'w:drawing') {
// Office 2011 Image
$xmlReader->registerNamespace('wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing');
$xmlReader->registerNamespace('r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$xmlReader->registerNamespace('pic', 'http://schemas.openxmlformats.org/drawingml/2006/picture');
$xmlReader->registerNamespace('a', 'http://schemas.openxmlformats.org/drawingml/2006/main');
$name = $xmlReader->getAttribute('name', $node, 'wp:inline/a:graphic/a:graphicData/pic:pic/pic:nvPicPr/pic:cNvPr');
$embedId = $xmlReader->getAttribute('r:embed', $node, 'wp:inline/a:graphic/a:graphicData/pic:pic/pic:blipFill/a:blip');
if ($name === null && $embedId === null) { // some Converters puts images on a different path
$name = $xmlReader->getAttribute('name', $node, 'wp:anchor/a:graphic/a:graphicData/pic:pic/pic:nvPicPr/pic:cNvPr');
$embedId = $xmlReader->getAttribute('r:embed', $node, 'wp:anchor/a:graphic/a:graphicData/pic:pic/pic:blipFill/a:blip');
}
$target = $this->getMediaTarget($docPart, $embedId);
if (!is_null($target)) {
$imageSource = "zip://{$this->docFile}#{$target}";
$parent->addImage($imageSource, null, false, $name);
}
} elseif ($node->nodeName == 'w:object') {
// Object
$rId = $xmlReader->getAttribute('r:id', $node, 'o:OLEObject');
// $rIdIcon = $xmlReader->getAttribute('r:id', $domNode, 'w:object/v:shape/v:imagedata');
$target = $this->getMediaTarget($docPart, $rId);
if (!is_null($target)) {
$textContent = "&lt;Object: {$target}>";
$parent->addText($textContent, $fontStyle, $paragraphStyle);
}
} elseif ($node->nodeName == 'w:br') {
$parent->addTextBreak();
} elseif ($node->nodeName == 'w:tab') {
$parent->addText("\t");
} elseif ($node->nodeName == 'mc:AlternateContent') {
if ($node->hasChildNodes()) {
// Get fallback instead of mc:Choice to make sure it is compatible
$fallbackElements = $node->getElementsByTagName('Fallback');
if ($fallbackElements->length) {
$fallback = $fallbackElements->item(0);
// TextRun
$textContent = htmlspecialchars($fallback->nodeValue, ENT_QUOTES, 'UTF-8');
$parent->addText($textContent, $fontStyle, $paragraphStyle);
}
}
} elseif ($node->nodeName == 'w:t' || $node->nodeName == 'w:delText') {
// TextRun
$textContent = htmlspecialchars($xmlReader->getValue('.', $node), ENT_QUOTES, 'UTF-8');
if ($runParent->nodeName == 'w:hyperlink') {
$rId = $xmlReader->getAttribute('r:id', $runParent);
$target = $this->getMediaTarget($docPart, $rId);
if (!is_null($target)) {
$parent->addLink($target, $textContent, $fontStyle, $paragraphStyle);
} else {
$parent->addText($textContent, $fontStyle, $paragraphStyle);
}
} else {
/** @var AbstractElement $element */
$element = $parent->addText($textContent, $fontStyle, $paragraphStyle);
if (in_array($runParent->nodeName, array('w:ins', 'w:del'))) {
$type = ($runParent->nodeName == 'w:del') ? TrackChange::DELETED : TrackChange::INSERTED;
$author = $runParent->getAttribute('w:author');
$date = \DateTime::createFromFormat('Y-m-d\TH:i:s\Z', $runParent->getAttribute('w:date'));
$element->setChangeInfo($type, $author, $date);
}
}
}
}
/**
* Read w:tbl.
*
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode
* @param mixed $parent
* @param string $docPart
*/
protected function readTable(XMLReader $xmlReader, \DOMElement $domNode, $parent, $docPart = 'document')
{
// Table style
$tblStyle = null;
if ($xmlReader->elementExists('w:tblPr', $domNode)) {
$tblStyle = $this->readTableStyle($xmlReader, $domNode);
}
/** @var \PhpOffice\PhpWord\Element\Table $table Type hint */
$table = $parent->addTable($tblStyle);
$tblNodes = $xmlReader->getElements('*', $domNode);
foreach ($tblNodes as $tblNode) {
if ('w:tblGrid' == $tblNode->nodeName) { // Column
// @todo Do something with table columns
} elseif ('w:tr' == $tblNode->nodeName) { // Row
$rowHeight = $xmlReader->getAttribute('w:val', $tblNode, 'w:trPr/w:trHeight');
$rowHRule = $xmlReader->getAttribute('w:hRule', $tblNode, 'w:trPr/w:trHeight');
$rowHRule = $rowHRule == 'exact';
$rowStyle = array(
'tblHeader' => $xmlReader->elementExists('w:trPr/w:tblHeader', $tblNode),
'cantSplit' => $xmlReader->elementExists('w:trPr/w:cantSplit', $tblNode),
'exactHeight' => $rowHRule,
);
$row = $table->addRow($rowHeight, $rowStyle);
$rowNodes = $xmlReader->getElements('*', $tblNode);
foreach ($rowNodes as $rowNode) {
if ('w:trPr' == $rowNode->nodeName) { // Row style
// @todo Do something with row style
} elseif ('w:tc' == $rowNode->nodeName) { // Cell
$cellWidth = $xmlReader->getAttribute('w:w', $rowNode, 'w:tcPr/w:tcW');
$cellStyle = null;
$cellStyleNode = $xmlReader->getElement('w:tcPr', $rowNode);
if (!is_null($cellStyleNode)) {
$cellStyle = $this->readCellStyle($xmlReader, $cellStyleNode);
}
$cell = $row->addCell($cellWidth, $cellStyle);
$cellNodes = $xmlReader->getElements('*', $rowNode);
foreach ($cellNodes as $cellNode) {
if ('w:p' == $cellNode->nodeName) { // Paragraph
$this->readParagraph($xmlReader, $cellNode, $cell, $docPart);
}
}
}
}
}
}
}
/**
* Read w:pPr.
*
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode
* @return array|null
*/
protected function readParagraphStyle(XMLReader $xmlReader, \DOMElement $domNode)
{
if (!$xmlReader->elementExists('w:pPr', $domNode)) {
return null;
}
$styleNode = $xmlReader->getElement('w:pPr', $domNode);
$styleDefs = array(
'styleName' => array(self::READ_VALUE, array('w:pStyle', 'w:name')),
'alignment' => array(self::READ_VALUE, 'w:jc'),
'basedOn' => array(self::READ_VALUE, 'w:basedOn'),
'next' => array(self::READ_VALUE, 'w:next'),
'indent' => array(self::READ_VALUE, 'w:ind', 'w:left'),
'hanging' => array(self::READ_VALUE, 'w:ind', 'w:hanging'),
'spaceAfter' => array(self::READ_VALUE, 'w:spacing', 'w:after'),
'spaceBefore' => array(self::READ_VALUE, 'w:spacing', 'w:before'),
'widowControl' => array(self::READ_FALSE, 'w:widowControl'),
'keepNext' => array(self::READ_TRUE, 'w:keepNext'),
'keepLines' => array(self::READ_TRUE, 'w:keepLines'),
'pageBreakBefore' => array(self::READ_TRUE, 'w:pageBreakBefore'),
'contextualSpacing' => array(self::READ_TRUE, 'w:contextualSpacing'),
'bidi' => array(self::READ_TRUE, 'w:bidi'),
'suppressAutoHyphens' => array(self::READ_TRUE, 'w:suppressAutoHyphens'),
);
return $this->readStyleDefs($xmlReader, $styleNode, $styleDefs);
}
/**
* Read w:rPr
*
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode
* @return array|null
*/
protected function readFontStyle(XMLReader $xmlReader, \DOMElement $domNode)
{
if (is_null($domNode)) {
return null;
}
// Hyperlink has an extra w:r child
if ('w:hyperlink' == $domNode->nodeName) {
$domNode = $xmlReader->getElement('w:r', $domNode);
}
if (!$xmlReader->elementExists('w:rPr', $domNode)) {
return null;
}
$styleNode = $xmlReader->getElement('w:rPr', $domNode);
$styleDefs = array(
'styleName' => array(self::READ_VALUE, 'w:rStyle'),
'name' => array(self::READ_VALUE, 'w:rFonts', array('w:ascii', 'w:hAnsi', 'w:eastAsia', 'w:cs')),
'hint' => array(self::READ_VALUE, 'w:rFonts', 'w:hint'),
'size' => array(self::READ_SIZE, array('w:sz', 'w:szCs')),
'color' => array(self::READ_VALUE, 'w:color'),
'underline' => array(self::READ_VALUE, 'w:u'),
'bold' => array(self::READ_TRUE, 'w:b'),
'italic' => array(self::READ_TRUE, 'w:i'),
'strikethrough' => array(self::READ_TRUE, 'w:strike'),
'doubleStrikethrough' => array(self::READ_TRUE, 'w:dstrike'),
'smallCaps' => array(self::READ_TRUE, 'w:smallCaps'),
'allCaps' => array(self::READ_TRUE, 'w:caps'),
'superScript' => array(self::READ_EQUAL, 'w:vertAlign', 'w:val', 'superscript'),
'subScript' => array(self::READ_EQUAL, 'w:vertAlign', 'w:val', 'subscript'),
'fgColor' => array(self::READ_VALUE, 'w:highlight'),
'rtl' => array(self::READ_TRUE, 'w:rtl'),
'lang' => array(self::READ_VALUE, 'w:lang'),
'position' => array(self::READ_VALUE, 'w:position'),
'hidden' => array(self::READ_TRUE, 'w:vanish'),
);
return $this->readStyleDefs($xmlReader, $styleNode, $styleDefs);
}
/**
* Read w:tblPr
*
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode
* @return string|array|null
* @todo Capture w:tblStylePr w:type="firstRow"
*/
protected function readTableStyle(XMLReader $xmlReader, \DOMElement $domNode)
{
$style = null;
$margins = array('top', 'left', 'bottom', 'right');
$borders = array_merge($margins, array('insideH', 'insideV'));
if ($xmlReader->elementExists('w:tblPr', $domNode)) {
if ($xmlReader->elementExists('w:tblPr/w:tblStyle', $domNode)) {
$style = $xmlReader->getAttribute('w:val', $domNode, 'w:tblPr/w:tblStyle');
} else {
$styleNode = $xmlReader->getElement('w:tblPr', $domNode);
$styleDefs = array();
foreach ($margins as $side) {
$ucfSide = ucfirst($side);
$styleDefs["cellMargin$ucfSide"] = array(self::READ_VALUE, "w:tblCellMar/w:$side", 'w:w');
}
foreach ($borders as $side) {
$ucfSide = ucfirst($side);
$styleDefs["border{$ucfSide}Size"] = array(self::READ_VALUE, "w:tblBorders/w:$side", 'w:sz');
$styleDefs["border{$ucfSide}Color"] = array(self::READ_VALUE, "w:tblBorders/w:$side", 'w:color');
$styleDefs["border{$ucfSide}Style"] = array(self::READ_VALUE, "w:tblBorders/w:$side", 'w:val');
}
$styleDefs['layout'] = array(self::READ_VALUE, 'w:tblLayout', 'w:type');
$styleDefs['bidiVisual'] = array(self::READ_TRUE, 'w:bidiVisual');
$styleDefs['cellSpacing'] = array(self::READ_VALUE, 'w:tblCellSpacing', 'w:w');
$style = $this->readStyleDefs($xmlReader, $styleNode, $styleDefs);
$tablePositionNode = $xmlReader->getElement('w:tblpPr', $styleNode);
if ($tablePositionNode !== null) {
$style['position'] = $this->readTablePosition($xmlReader, $tablePositionNode);
}
$indentNode = $xmlReader->getElement('w:tblInd', $styleNode);
if ($indentNode !== null) {
$style['indent'] = $this->readTableIndent($xmlReader, $indentNode);
}
}
}
return $style;
}
/**
* Read w:tblpPr
*
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode
* @return array
*/
private function readTablePosition(XMLReader $xmlReader, \DOMElement $domNode)
{
$styleDefs = array(
'leftFromText' => array(self::READ_VALUE, '.', 'w:leftFromText'),
'rightFromText' => array(self::READ_VALUE, '.', 'w:rightFromText'),
'topFromText' => array(self::READ_VALUE, '.', 'w:topFromText'),
'bottomFromText' => array(self::READ_VALUE, '.', 'w:bottomFromText'),
'vertAnchor' => array(self::READ_VALUE, '.', 'w:vertAnchor'),
'horzAnchor' => array(self::READ_VALUE, '.', 'w:horzAnchor'),
'tblpXSpec' => array(self::READ_VALUE, '.', 'w:tblpXSpec'),
'tblpX' => array(self::READ_VALUE, '.', 'w:tblpX'),
'tblpYSpec' => array(self::READ_VALUE, '.', 'w:tblpYSpec'),
'tblpY' => array(self::READ_VALUE, '.', 'w:tblpY'),
);
return $this->readStyleDefs($xmlReader, $domNode, $styleDefs);
}
/**
* Read w:tblInd
*
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode
* @return TblWidthComplexType
*/
private function readTableIndent(XMLReader $xmlReader, \DOMElement $domNode)
{
$styleDefs = array(
'value' => array(self::READ_VALUE, '.', 'w:w'),
'type' => array(self::READ_VALUE, '.', 'w:type'),
);
$styleDefs = $this->readStyleDefs($xmlReader, $domNode, $styleDefs);
return new TblWidthComplexType((int) $styleDefs['value'], $styleDefs['type']);
}
/**
* Read w:tcPr
*
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode
* @return array
*/
private function readCellStyle(XMLReader $xmlReader, \DOMElement $domNode)
{
$styleDefs = array(
'valign' => array(self::READ_VALUE, 'w:vAlign'),
'textDirection' => array(self::READ_VALUE, 'w:textDirection'),
'gridSpan' => array(self::READ_VALUE, 'w:gridSpan'),
'vMerge' => array(self::READ_VALUE, 'w:vMerge'),
'bgColor' => array(self::READ_VALUE, 'w:shd', 'w:fill'),
);
return $this->readStyleDefs($xmlReader, $domNode, $styleDefs);
}
/**
* Returns the first child element found
*
* @param XMLReader $xmlReader
* @param \DOMElement|null $parentNode
* @param string|array|null $elements
* @return string|null
*/
private function findPossibleElement(XMLReader $xmlReader, \DOMElement $parentNode = null, $elements = null)
{
if (is_array($elements)) {
//if element is an array, we take the first element that exists in the XML
foreach ($elements as $possibleElement) {
if ($xmlReader->elementExists($possibleElement, $parentNode)) {
return $possibleElement;
}
}
} else {
return $elements;
}
return null;
}
/**
* Returns the first attribute found
*
* @param XMLReader $xmlReader
* @param \DOMElement $node
* @param string|array $attributes
* @return string|null
*/
private function findPossibleAttribute(XMLReader $xmlReader, \DOMElement $node, $attributes)
{
//if attribute is an array, we take the first attribute that exists in the XML
if (is_array($attributes)) {
foreach ($attributes as $possibleAttribute) {
if ($xmlReader->getAttribute($possibleAttribute, $node)) {
return $possibleAttribute;
}
}
return null;
}
return $attributes;
}
/**
* Read style definition
*
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $parentNode
* @param array $styleDefs
* @ignoreScrutinizerPatch
* @return array
*/
protected function readStyleDefs(XMLReader $xmlReader, \DOMElement $parentNode = null, $styleDefs = array())
{
$styles = array();
foreach ($styleDefs as $styleProp => $styleVal) {
list($method, $element, $attribute, $expected) = array_pad($styleVal, 4, null);
$element = $this->findPossibleElement($xmlReader, $parentNode, $element);
if ($element === null) {
continue;
}
if ($xmlReader->elementExists($element, $parentNode)) {
$node = $xmlReader->getElement($element, $parentNode);
$attribute = $this->findPossibleAttribute($xmlReader, $node, $attribute);
// Use w:val as default if no attribute assigned
$attribute = ($attribute === null) ? 'w:val' : $attribute;
$attributeValue = $xmlReader->getAttribute($attribute, $node);
$styleValue = $this->readStyleDef($method, $attributeValue, $expected);
if ($styleValue !== null) {
$styles[$styleProp] = $styleValue;
}
}
}
return $styles;
}
/**
* Return style definition based on conversion method
*
* @param string $method
* @ignoreScrutinizerPatch
* @param string|null $attributeValue
* @param mixed $expected
* @return mixed
*/
private function readStyleDef($method, $attributeValue, $expected)
{
$style = $attributeValue;
if (self::READ_SIZE == $method) {
$style = $attributeValue / 2;
} elseif (self::READ_TRUE == $method) {
$style = $this->isOn($attributeValue);
} elseif (self::READ_FALSE == $method) {
$style = !$this->isOn($attributeValue);
} elseif (self::READ_EQUAL == $method) {
$style = $attributeValue == $expected;
}
return $style;
}
/**
* Parses the value of the on/off value, null is considered true as it means the w:val attribute was not present
*
* @see http://www.datypic.com/sc/ooxml/t-w_ST_OnOff.html
* @param string $value
* @return bool
*/
private function isOn($value = null)
{
return $value === null || $value === '1' || $value === 'true' || $value === 'on';
}
/**
* Returns the target of image, object, or link as stored in ::readMainRels
*
* @param string $docPart
* @param string $rId
* @return string|null
*/
private function getMediaTarget($docPart, $rId)
{
$target = null;
if (isset($this->rels[$docPart]) && isset($this->rels[$docPart][$rId])) {
$target = $this->rels[$docPart][$rId]['target'];
}
return $target;
}
/**
* Returns the target mode
*
* @param string $docPart
* @param string $rId
* @return string|null
*/
private function getTargetMode($docPart, $rId)
{
$mode = null;
if (isset($this->rels[$docPart]) && isset($this->rels[$docPart][$rId])) {
$mode = $this->rels[$docPart][$rId]['targetMode'];
}
return $mode;
}
}

View File

@@ -0,0 +1,40 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Reader\Word2007;
/**
* Extended properties reader
*
* @since 0.10.0
*/
class DocPropsApp extends DocPropsCore
{
/**
* Property mapping
*
* @var array
*/
protected $mapping = array('Company' => 'setCompany', 'Manager' => 'setManager');
/**
* Callback functions
*
* @var array
*/
protected $callbacks = array();
}

View File

@@ -0,0 +1,83 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Reader\Word2007;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLReader;
/**
* Core properties reader
*
* @since 0.10.0
*/
class DocPropsCore extends AbstractPart
{
/**
* Property mapping
*
* @var array
*/
protected $mapping = array(
'dc:creator' => 'setCreator',
'dc:title' => 'setTitle',
'dc:description' => 'setDescription',
'dc:subject' => 'setSubject',
'cp:keywords' => 'setKeywords',
'cp:category' => 'setCategory',
'cp:lastModifiedBy' => 'setLastModifiedBy',
'dcterms:created' => 'setCreated',
'dcterms:modified' => 'setModified',
);
/**
* Callback functions
*
* @var array
*/
protected $callbacks = array('dcterms:created' => 'strtotime', 'dcterms:modified' => 'strtotime');
/**
* Read core/extended document properties.
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
*/
public function read(PhpWord $phpWord)
{
$xmlReader = new XMLReader();
$xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
$docProps = $phpWord->getDocInfo();
$nodes = $xmlReader->getElements('*');
if ($nodes->length > 0) {
foreach ($nodes as $node) {
if (!isset($this->mapping[$node->nodeName])) {
continue;
}
$method = $this->mapping[$node->nodeName];
$value = $node->nodeValue == '' ? null : $node->nodeValue;
if (isset($this->callbacks[$node->nodeName])) {
$value = $this->callbacks[$node->nodeName]($value);
}
if (method_exists($docProps, $method)) {
$docProps->$method($value);
}
}
}
}
}

View File

@@ -0,0 +1,55 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Reader\Word2007;
use PhpOffice\PhpWord\Metadata\DocInfo;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLReader;
/**
* Custom properties reader
*
* @since 0.11.0
*/
class DocPropsCustom extends AbstractPart
{
/**
* Read custom document properties.
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
*/
public function read(PhpWord $phpWord)
{
$xmlReader = new XMLReader();
$xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
$docProps = $phpWord->getDocInfo();
$nodes = $xmlReader->getElements('*');
if ($nodes->length > 0) {
foreach ($nodes as $node) {
$propertyName = $xmlReader->getAttribute('name', $node);
$attributeNode = $xmlReader->getElement('*', $node);
$attributeType = $attributeNode->nodeName;
$attributeValue = $attributeNode->nodeValue;
$attributeValue = DocInfo::convertProperty($attributeValue, $attributeType);
$attributeType = DocInfo::convertPropertyType($attributeType);
$docProps->setCustomProperty($propertyName, $attributeValue, $attributeType);
}
}
}
}

View File

@@ -0,0 +1,183 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Reader\Word2007;
use PhpOffice\PhpWord\Element\Section;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLReader;
/**
* Document reader
*
* @since 0.10.0
* @SuppressWarnings(PHPMD.UnusedPrivateMethod) For readWPNode
*/
class Document extends AbstractPart
{
/**
* PhpWord object
*
* @var \PhpOffice\PhpWord\PhpWord
*/
private $phpWord;
/**
* Read document.xml.
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
*/
public function read(PhpWord $phpWord)
{
$this->phpWord = $phpWord;
$xmlReader = new XMLReader();
$xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
$readMethods = array('w:p' => 'readWPNode', 'w:tbl' => 'readTable', 'w:sectPr' => 'readWSectPrNode');
$nodes = $xmlReader->getElements('w:body/*');
if ($nodes->length > 0) {
$section = $this->phpWord->addSection();
foreach ($nodes as $node) {
if (isset($readMethods[$node->nodeName])) {
$readMethod = $readMethods[$node->nodeName];
$this->$readMethod($xmlReader, $node, $section);
}
}
}
}
/**
* Read header footer.
*
* @param array $settings
* @param \PhpOffice\PhpWord\Element\Section &$section
*/
private function readHeaderFooter($settings, Section &$section)
{
$readMethods = array('w:p' => 'readParagraph', 'w:tbl' => 'readTable');
if (is_array($settings) && isset($settings['hf'])) {
foreach ($settings['hf'] as $rId => $hfSetting) {
if (isset($this->rels['document'][$rId])) {
list($hfType, $xmlFile, $docPart) = array_values($this->rels['document'][$rId]);
$addMethod = "add{$hfType}";
$hfObject = $section->$addMethod($hfSetting['type']);
// Read header/footer content
$xmlReader = new XMLReader();
$xmlReader->getDomFromZip($this->docFile, $xmlFile);
$nodes = $xmlReader->getElements('*');
if ($nodes->length > 0) {
foreach ($nodes as $node) {
if (isset($readMethods[$node->nodeName])) {
$readMethod = $readMethods[$node->nodeName];
$this->$readMethod($xmlReader, $node, $hfObject, $docPart);
}
}
}
}
}
}
}
/**
* Read w:sectPr
*
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode
* @ignoreScrutinizerPatch
* @return array
*/
private function readSectionStyle(XMLReader $xmlReader, \DOMElement $domNode)
{
$styleDefs = array(
'breakType' => array(self::READ_VALUE, 'w:type'),
'vAlign' => array(self::READ_VALUE, 'w:vAlign'),
'pageSizeW' => array(self::READ_VALUE, 'w:pgSz', 'w:w'),
'pageSizeH' => array(self::READ_VALUE, 'w:pgSz', 'w:h'),
'orientation' => array(self::READ_VALUE, 'w:pgSz', 'w:orient'),
'colsNum' => array(self::READ_VALUE, 'w:cols', 'w:num'),
'colsSpace' => array(self::READ_VALUE, 'w:cols', 'w:space'),
'marginTop' => array(self::READ_VALUE, 'w:pgMar', 'w:top'),
'marginLeft' => array(self::READ_VALUE, 'w:pgMar', 'w:left'),
'marginBottom' => array(self::READ_VALUE, 'w:pgMar', 'w:bottom'),
'marginRight' => array(self::READ_VALUE, 'w:pgMar', 'w:right'),
'headerHeight' => array(self::READ_VALUE, 'w:pgMar', 'w:header'),
'footerHeight' => array(self::READ_VALUE, 'w:pgMar', 'w:footer'),
'gutter' => array(self::READ_VALUE, 'w:pgMar', 'w:gutter'),
);
$styles = $this->readStyleDefs($xmlReader, $domNode, $styleDefs);
// Header and footer
// @todo Cleanup this part
$nodes = $xmlReader->getElements('*', $domNode);
foreach ($nodes as $node) {
if ($node->nodeName == 'w:headerReference' || $node->nodeName == 'w:footerReference') {
$id = $xmlReader->getAttribute('r:id', $node);
$styles['hf'][$id] = array(
'method' => str_replace('w:', '', str_replace('Reference', '', $node->nodeName)),
'type' => $xmlReader->getAttribute('w:type', $node),
);
}
}
return $styles;
}
/**
* Read w:p node.
*
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $node
* @param \PhpOffice\PhpWord\Element\Section &$section
*
* @todo <w:lastRenderedPageBreak>
*/
private function readWPNode(XMLReader $xmlReader, \DOMElement $node, Section &$section)
{
// Page break
if ($xmlReader->getAttribute('w:type', $node, 'w:r/w:br') == 'page') {
$section->addPageBreak(); // PageBreak
}
// Paragraph
$this->readParagraph($xmlReader, $node, $section);
// Section properties
if ($xmlReader->elementExists('w:pPr/w:sectPr', $node)) {
$sectPrNode = $xmlReader->getElement('w:pPr/w:sectPr', $node);
if ($sectPrNode !== null) {
$this->readWSectPrNode($xmlReader, $sectPrNode, $section);
}
$section = $this->phpWord->addSection();
}
}
/**
* Read w:sectPr node.
*
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $node
* @param \PhpOffice\PhpWord\Element\Section &$section
*/
private function readWSectPrNode(XMLReader $xmlReader, \DOMElement $node, Section &$section)
{
$style = $this->readSectionStyle($xmlReader, $node);
$section->setStyle($style);
$this->readHeaderFooter($style, $section);
}
}

View File

@@ -0,0 +1,40 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Reader\Word2007;
/**
* Endnotes reader
*
* @since 0.10.0
*/
class Endnotes extends Footnotes
{
/**
* Collection name
*
* @var string
*/
protected $collection = 'endnotes';
/**
* Element name
*
* @var string
*/
protected $element = 'endnote';
}

View File

@@ -0,0 +1,97 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Reader\Word2007;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLReader;
/**
* Footnotes reader
*
* @since 0.10.0
*/
class Footnotes extends AbstractPart
{
/**
* Collection name footnotes|endnotes
*
* @var string
*/
protected $collection = 'footnotes';
/**
* Element name footnote|endnote
*
* @var string
*/
protected $element = 'footnote';
/**
* Read (footnotes|endnotes).xml.
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
*/
public function read(PhpWord $phpWord)
{
$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, or with w:type = normal
if ((is_null($type) || $type === 'normal')) {
$element = $this->getElement($phpWord, $id);
if ($element !== null) {
$pNodes = $xmlReader->getElements('w:p/*', $node);
foreach ($pNodes as $pNode) {
$this->readRun($xmlReader, $pNode, $element, $this->collection);
}
$addMethod = "add{$this->element}";
$phpWord->$addMethod($element);
}
}
}
}
}
/**
* Searches for the element with the given relationId
*
* @param PhpWord $phpWord
* @param int $relationId
* @return \PhpOffice\PhpWord\Element\AbstractContainer|null
*/
private function getElement(PhpWord $phpWord, $relationId)
{
$getMethod = "get{$this->collection}";
$collection = $phpWord->$getMethod()->getItems();
//not found by key, looping to search by relationId
foreach ($collection as $collectionElement) {
if ($collectionElement->getRelationId() == $relationId) {
return $collectionElement;
}
}
return null;
}
}

View File

@@ -0,0 +1,122 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Reader\Word2007;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLReader;
/**
* Numbering reader
*
* @since 0.10.0
*/
class Numbering extends AbstractPart
{
/**
* Read numbering.xml.
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
*/
public function read(PhpWord $phpWord)
{
$abstracts = array();
$numberings = array();
$xmlReader = new XMLReader();
$xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
// Abstract numbering definition
$nodes = $xmlReader->getElements('w:abstractNum');
if ($nodes->length > 0) {
foreach ($nodes as $node) {
$abstractId = $xmlReader->getAttribute('w:abstractNumId', $node);
$abstracts[$abstractId] = array('levels' => array());
$abstract = &$abstracts[$abstractId];
$subnodes = $xmlReader->getElements('*', $node);
foreach ($subnodes as $subnode) {
switch ($subnode->nodeName) {
case 'w:multiLevelType':
$abstract['type'] = $xmlReader->getAttribute('w:val', $subnode);
break;
case 'w:lvl':
$levelId = $xmlReader->getAttribute('w:ilvl', $subnode);
$abstract['levels'][$levelId] = $this->readLevel($xmlReader, $subnode, $levelId);
break;
}
}
}
}
// Numbering instance definition
$nodes = $xmlReader->getElements('w:num');
if ($nodes->length > 0) {
foreach ($nodes as $node) {
$numId = $xmlReader->getAttribute('w:numId', $node);
$abstractId = $xmlReader->getAttribute('w:val', $node, 'w:abstractNumId');
$numberings[$numId] = $abstracts[$abstractId];
$numberings[$numId]['numId'] = $numId;
$subnodes = $xmlReader->getElements('w:lvlOverride/w:lvl', $node);
foreach ($subnodes as $subnode) {
$levelId = $xmlReader->getAttribute('w:ilvl', $subnode);
$overrides = $this->readLevel($xmlReader, $subnode, $levelId);
foreach ($overrides as $key => $value) {
$numberings[$numId]['levels'][$levelId][$key] = $value;
}
}
}
}
// Push to Style collection
foreach ($numberings as $numId => $numbering) {
$phpWord->addNumberingStyle("PHPWordList{$numId}", $numbering);
}
}
/**
* Read numbering level definition from w:abstractNum and w:num
*
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $subnode
* @param int $levelId
* @return array
*/
private function readLevel(XMLReader $xmlReader, \DOMElement $subnode, $levelId)
{
$level = array();
$level['level'] = $levelId;
$level['start'] = $xmlReader->getAttribute('w:val', $subnode, 'w:start');
$level['format'] = $xmlReader->getAttribute('w:val', $subnode, 'w:numFmt');
$level['restart'] = $xmlReader->getAttribute('w:val', $subnode, 'w:lvlRestart');
$level['suffix'] = $xmlReader->getAttribute('w:val', $subnode, 'w:suff');
$level['text'] = $xmlReader->getAttribute('w:val', $subnode, 'w:lvlText');
$level['alignment'] = $xmlReader->getAttribute('w:val', $subnode, 'w:lvlJc');
$level['tab'] = $xmlReader->getAttribute('w:pos', $subnode, 'w:pPr/w:tabs/w:tab');
$level['left'] = $xmlReader->getAttribute('w:left', $subnode, 'w:pPr/w:ind');
$level['hanging'] = $xmlReader->getAttribute('w:hanging', $subnode, 'w:pPr/w:ind');
$level['font'] = $xmlReader->getAttribute('w:ascii', $subnode, 'w:rPr/w:rFonts');
$level['hint'] = $xmlReader->getAttribute('w:hint', $subnode, 'w:rPr/w:rFonts');
foreach ($level as $key => $value) {
if (is_null($value)) {
unset($level[$key]);
}
}
return $level;
}
}

View File

@@ -0,0 +1,201 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Reader\Word2007;
use PhpOffice\PhpWord\ComplexType\TrackChangesView;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLReader;
use PhpOffice\PhpWord\Style\Language;
/**
* Settings reader
*
* @since 0.14.0
*/
class Settings extends AbstractPart
{
private static $booleanProperties = array(
'mirrorMargins',
'hideSpellingErrors',
'hideGrammaticalErrors',
'trackRevisions',
'doNotTrackMoves',
'doNotTrackFormatting',
'evenAndOddHeaders',
'updateFields',
'autoHyphenation',
'doNotHyphenateCaps',
);
/**
* Read settings.xml.
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
*/
public function read(PhpWord $phpWord)
{
$xmlReader = new XMLReader();
$xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
$docSettings = $phpWord->getSettings();
$nodes = $xmlReader->getElements('*');
if ($nodes->length > 0) {
foreach ($nodes as $node) {
$name = str_replace('w:', '', $node->nodeName);
$value = $xmlReader->getAttribute('w:val', $node);
$method = 'set' . $name;
if (in_array($name, $this::$booleanProperties)) {
if ($value == 'false') {
$docSettings->$method(false);
} else {
$docSettings->$method(true);
}
} elseif (method_exists($this, $method)) {
$this->$method($xmlReader, $phpWord, $node);
} elseif (method_exists($docSettings, $method)) {
$docSettings->$method($value);
}
}
}
}
/**
* Sets the document Language
*
* @param XMLReader $xmlReader
* @param PhpWord $phpWord
* @param \DOMElement $node
*/
protected function setThemeFontLang(XMLReader $xmlReader, PhpWord $phpWord, \DOMElement $node)
{
$val = $xmlReader->getAttribute('w:val', $node);
$eastAsia = $xmlReader->getAttribute('w:eastAsia', $node);
$bidi = $xmlReader->getAttribute('w:bidi', $node);
$themeFontLang = new Language();
$themeFontLang->setLatin($val);
$themeFontLang->setEastAsia($eastAsia);
$themeFontLang->setBidirectional($bidi);
$phpWord->getSettings()->setThemeFontLang($themeFontLang);
}
/**
* Sets the document protection
*
* @param XMLReader $xmlReader
* @param PhpWord $phpWord
* @param \DOMElement $node
*/
protected function setDocumentProtection(XMLReader $xmlReader, PhpWord $phpWord, \DOMElement $node)
{
$documentProtection = $phpWord->getSettings()->getDocumentProtection();
$edit = $xmlReader->getAttribute('w:edit', $node);
if ($edit !== null) {
$documentProtection->setEditing($edit);
}
}
/**
* Sets the proof state
*
* @param XMLReader $xmlReader
* @param PhpWord $phpWord
* @param \DOMElement $node
*/
protected function setProofState(XMLReader $xmlReader, PhpWord $phpWord, \DOMElement $node)
{
$proofState = $phpWord->getSettings()->getProofState();
$spelling = $xmlReader->getAttribute('w:spelling', $node);
$grammar = $xmlReader->getAttribute('w:grammar', $node);
if ($spelling !== null) {
$proofState->setSpelling($spelling);
}
if ($grammar !== null) {
$proofState->setGrammar($grammar);
}
}
/**
* Sets the proof state
*
* @param XMLReader $xmlReader
* @param PhpWord $phpWord
* @param \DOMElement $node
*/
protected function setZoom(XMLReader $xmlReader, PhpWord $phpWord, \DOMElement $node)
{
$percent = $xmlReader->getAttribute('w:percent', $node);
$val = $xmlReader->getAttribute('w:val', $node);
if ($percent !== null || $val !== null) {
$phpWord->getSettings()->setZoom($percent === null ? $val : $percent);
}
}
/**
* Set the Revision view
*
* @param XMLReader $xmlReader
* @param PhpWord $phpWord
* @param \DOMElement $node
*/
protected function setRevisionView(XMLReader $xmlReader, PhpWord $phpWord, \DOMElement $node)
{
$revisionView = new TrackChangesView();
$revisionView->setMarkup(filter_var($xmlReader->getAttribute('w:markup', $node), FILTER_VALIDATE_BOOLEAN));
$revisionView->setComments($xmlReader->getAttribute('w:comments', $node));
$revisionView->setInsDel(filter_var($xmlReader->getAttribute('w:insDel', $node), FILTER_VALIDATE_BOOLEAN));
$revisionView->setFormatting(filter_var($xmlReader->getAttribute('w:formatting', $node), FILTER_VALIDATE_BOOLEAN));
$revisionView->setInkAnnotations(filter_var($xmlReader->getAttribute('w:inkAnnotations', $node), FILTER_VALIDATE_BOOLEAN));
$phpWord->getSettings()->setRevisionView($revisionView);
}
/**
* @param XMLReader $xmlReader
* @param PhpWord $phpWord
* @param \DOMElement $node
*/
protected function setConsecutiveHyphenLimit(XMLReader $xmlReader, PhpWord $phpWord, \DOMElement $node)
{
$value = $xmlReader->getAttribute('w:val', $node);
if ($value !== null) {
$phpWord->getSettings()->setConsecutiveHyphenLimit($value);
}
}
/**
* @param XMLReader $xmlReader
* @param PhpWord $phpWord
* @param \DOMElement $node
*/
protected function setHyphenationZone(XMLReader $xmlReader, PhpWord $phpWord, \DOMElement $node)
{
$value = $xmlReader->getAttribute('w:val', $node);
if ($value !== null) {
$phpWord->getSettings()->setHyphenationZone($value);
}
}
}

View File

@@ -0,0 +1,106 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Reader\Word2007;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLReader;
use PhpOffice\PhpWord\Style\Language;
/**
* Styles reader
*
* @since 0.10.0
*/
class Styles extends AbstractPart
{
/**
* Read styles.xml.
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
*/
public function read(PhpWord $phpWord)
{
$xmlReader = new XMLReader();
$xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
$fontDefaults = $xmlReader->getElement('w:docDefaults/w:rPrDefault');
if ($fontDefaults !== null) {
$fontDefaultStyle = $this->readFontStyle($xmlReader, $fontDefaults);
if (array_key_exists('name', $fontDefaultStyle)) {
$phpWord->setDefaultFontName($fontDefaultStyle['name']);
}
if (array_key_exists('size', $fontDefaultStyle)) {
$phpWord->setDefaultFontSize($fontDefaultStyle['size']);
}
if (array_key_exists('lang', $fontDefaultStyle)) {
$phpWord->getSettings()->setThemeFontLang(new Language($fontDefaultStyle['lang']));
}
}
$paragraphDefaults = $xmlReader->getElement('w:docDefaults/w:pPrDefault');
if ($paragraphDefaults !== null) {
$paragraphDefaultStyle = $this->readParagraphStyle($xmlReader, $paragraphDefaults);
if ($paragraphDefaultStyle != null) {
$phpWord->setDefaultParagraphStyle($paragraphDefaultStyle);
}
}
$nodes = $xmlReader->getElements('w:style');
if ($nodes->length > 0) {
foreach ($nodes as $node) {
$type = $xmlReader->getAttribute('w:type', $node);
$name = $xmlReader->getAttribute('w:val', $node, 'w:name');
if (is_null($name)) {
$name = $xmlReader->getAttribute('w:styleId', $node);
}
$headingMatches = array();
preg_match('/Heading\s*(\d)/i', $name, $headingMatches);
// $default = ($xmlReader->getAttribute('w:default', $node) == 1);
switch ($type) {
case 'paragraph':
$paragraphStyle = $this->readParagraphStyle($xmlReader, $node);
$fontStyle = $this->readFontStyle($xmlReader, $node);
if (!empty($headingMatches)) {
$phpWord->addTitleStyle($headingMatches[1], $fontStyle, $paragraphStyle);
} else {
if (empty($fontStyle)) {
if (is_array($paragraphStyle)) {
$phpWord->addParagraphStyle($name, $paragraphStyle);
}
} else {
$phpWord->addFontStyle($name, $fontStyle, $paragraphStyle);
}
}
break;
case 'character':
$fontStyle = $this->readFontStyle($xmlReader, $node);
if (!empty($fontStyle)) {
$phpWord->addFontStyle($name, $fontStyle);
}
break;
case 'table':
$tStyle = $this->readTableStyle($xmlReader, $node);
if (!empty($tStyle)) {
$phpWord->addTableStyle($name, $tStyle);
}
break;
}
}
}
}
}

View File

@@ -0,0 +1,480 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord;
/**
* PHPWord settings class
*
* @since 0.8.0
*/
class Settings
{
/**
* Zip libraries
*
* @const string
*/
const ZIPARCHIVE = 'ZipArchive';
const PCLZIP = 'PclZip';
const OLD_LIB = 'PhpOffice\\PhpWord\\Shared\\ZipArchive'; // @deprecated 0.11
/**
* PDF rendering libraries
*
* @const string
*/
const PDF_RENDERER_DOMPDF = 'DomPDF';
const PDF_RENDERER_TCPDF = 'TCPDF';
const PDF_RENDERER_MPDF = 'MPDF';
/**
* Measurement units multiplication factor
*
* Applied to:
* - Section: margins, header/footer height, gutter, column spacing
* - Tab: position
* - Indentation: left, right, firstLine, hanging
* - Spacing: before, after
*
* @const string
*/
const UNIT_TWIP = 'twip'; // = 1/20 point
const UNIT_CM = 'cm';
const UNIT_MM = 'mm';
const UNIT_INCH = 'inch';
const UNIT_POINT = 'point'; // = 1/72 inch
const UNIT_PICA = 'pica'; // = 1/6 inch = 12 points
/**
* Default font settings
*
* OOXML defined font size values in halfpoints, i.e. twice of what PhpWord
* use, and the conversion will be conducted during XML writing.
*/
const DEFAULT_FONT_NAME = 'Arial';
const DEFAULT_FONT_SIZE = 10;
const DEFAULT_FONT_COLOR = '000000';
const DEFAULT_FONT_CONTENT_TYPE = 'default'; // default|eastAsia|cs
const DEFAULT_PAPER = 'A4';
/**
* Compatibility option for XMLWriter
*
* @var bool
*/
private static $xmlWriterCompatibility = true;
/**
* Name of the class used for Zip file management
*
* @var string
*/
private static $zipClass = self::ZIPARCHIVE;
/**
* Name of the external Library used for rendering PDF files
*
* @var string
*/
private static $pdfRendererName = null;
/**
* Directory Path to the external Library used for rendering PDF files
*
* @var string
*/
private static $pdfRendererPath = null;
/**
* Measurement unit
*
* @var int|float
*/
private static $measurementUnit = self::UNIT_TWIP;
/**
* Default font name
*
* @var string
*/
private static $defaultFontName = self::DEFAULT_FONT_NAME;
/**
* Default font size
* @var int
*/
private static $defaultFontSize = self::DEFAULT_FONT_SIZE;
/**
* Default paper
* @var string
*/
private static $defaultPaper = self::DEFAULT_PAPER;
/**
* The user defined temporary directory.
*
* @var string
*/
private static $tempDir = '';
/**
* Enables built-in output escaping mechanism.
* Default value is `false` for backward compatibility with versions below 0.13.0.
*
* @var bool
*/
private static $outputEscapingEnabled = false;
/**
* Return the compatibility option used by the XMLWriter
*
* @return bool Compatibility
*/
public static function hasCompatibility()
{
return self::$xmlWriterCompatibility;
}
/**
* Set the compatibility option used by the XMLWriter
*
* This sets the setIndent and setIndentString for better compatibility
*
* @param bool $compatibility
* @return bool
*/
public static function setCompatibility($compatibility)
{
$compatibility = (bool) $compatibility;
self::$xmlWriterCompatibility = $compatibility;
return true;
}
/**
* Get zip handler class
*
* @return string
*/
public static function getZipClass()
{
return self::$zipClass;
}
/**
* Set zip handler class
*
* @param string $zipClass
* @return bool
*/
public static function setZipClass($zipClass)
{
if (in_array($zipClass, array(self::PCLZIP, self::ZIPARCHIVE, self::OLD_LIB))) {
self::$zipClass = $zipClass;
return true;
}
return false;
}
/**
* Set details of the external library for rendering PDF files
*
* @param string $libraryName
* @param string $libraryBaseDir
* @return bool Success or failure
*/
public static function setPdfRenderer($libraryName, $libraryBaseDir)
{
if (!self::setPdfRendererName($libraryName)) {
return false;
}
return self::setPdfRendererPath($libraryBaseDir);
}
/**
* Return the PDF Rendering Library.
*
* @return string
*/
public static function getPdfRendererName()
{
return self::$pdfRendererName;
}
/**
* Identify the external library to use for rendering PDF files
*
* @param string $libraryName
* @return bool
*/
public static function setPdfRendererName($libraryName)
{
$pdfRenderers = array(self::PDF_RENDERER_DOMPDF, self::PDF_RENDERER_TCPDF, self::PDF_RENDERER_MPDF);
if (!in_array($libraryName, $pdfRenderers)) {
return false;
}
self::$pdfRendererName = $libraryName;
return true;
}
/**
* Return the directory path to the PDF Rendering Library.
*
* @return string
*/
public static function getPdfRendererPath()
{
return self::$pdfRendererPath;
}
/**
* Location of external library to use for rendering PDF files
*
* @param string $libraryBaseDir Directory path to the library's base folder
* @return bool Success or failure
*/
public static function setPdfRendererPath($libraryBaseDir)
{
if (false === file_exists($libraryBaseDir) || false === is_readable($libraryBaseDir)) {
return false;
}
self::$pdfRendererPath = $libraryBaseDir;
return true;
}
/**
* Get measurement unit
*
* @return string
*/
public static function getMeasurementUnit()
{
return self::$measurementUnit;
}
/**
* Set measurement unit
*
* @param string $value
* @return bool
*/
public static function setMeasurementUnit($value)
{
$units = array(self::UNIT_TWIP, self::UNIT_CM, self::UNIT_MM, self::UNIT_INCH,
self::UNIT_POINT, self::UNIT_PICA, );
if (!in_array($value, $units)) {
return false;
}
self::$measurementUnit = $value;
return true;
}
/**
* Sets the user defined path to temporary directory.
*
* @since 0.12.0
*
* @param string $tempDir The user defined path to temporary directory
*/
public static function setTempDir($tempDir)
{
self::$tempDir = $tempDir;
}
/**
* Returns path to temporary directory.
*
* @since 0.12.0
*
* @return string
*/
public static function getTempDir()
{
if (!empty(self::$tempDir)) {
$tempDir = self::$tempDir;
} else {
$tempDir = sys_get_temp_dir();
}
return $tempDir;
}
/**
* @since 0.13.0
*
* @return bool
*/
public static function isOutputEscapingEnabled()
{
return self::$outputEscapingEnabled;
}
/**
* @since 0.13.0
*
* @param bool $outputEscapingEnabled
*/
public static function setOutputEscapingEnabled($outputEscapingEnabled)
{
self::$outputEscapingEnabled = $outputEscapingEnabled;
}
/**
* Get default font name
*
* @return string
*/
public static function getDefaultFontName()
{
return self::$defaultFontName;
}
/**
* Set default font name
*
* @param string $value
* @return bool
*/
public static function setDefaultFontName($value)
{
if (is_string($value) && trim($value) !== '') {
self::$defaultFontName = $value;
return true;
}
return false;
}
/**
* Get default font size
*
* @return int
*/
public static function getDefaultFontSize()
{
return self::$defaultFontSize;
}
/**
* Set default font size
*
* @param int $value
* @return bool
*/
public static function setDefaultFontSize($value)
{
$value = (int) $value;
if ($value > 0) {
self::$defaultFontSize = $value;
return true;
}
return false;
}
/**
* Load setting from phpword.yml or phpword.yml.dist
*
* @param string $filename
* @return array
*/
public static function loadConfig($filename = null)
{
// Get config file
$configFile = null;
$configPath = __DIR__ . '/../../';
if ($filename !== null) {
$files = array($filename);
} else {
$files = array("{$configPath}phpword.ini", "{$configPath}phpword.ini.dist");
}
foreach ($files as $file) {
if (file_exists($file)) {
$configFile = realpath($file);
break;
}
}
// Parse config file
$config = array();
if ($configFile !== null) {
$config = @parse_ini_file($configFile);
if ($config === false) {
return $config;
}
}
// Set config value
foreach ($config as $key => $value) {
$method = "set{$key}";
if (method_exists(__CLASS__, $method)) {
self::$method($value);
}
}
return $config;
}
/**
* Get default paper
*
* @return string
*/
public static function getDefaultPaper()
{
return self::$defaultPaper;
}
/**
* Set default paper
*
* @param string $value
* @return bool
*/
public static function setDefaultPaper($value)
{
if (is_string($value) && trim($value) !== '') {
self::$defaultPaper = $value;
return true;
}
return false;
}
/**
* Return the compatibility option used by the XMLWriter
*
* @deprecated 0.10.0
*
* @codeCoverageIgnore
*/
public static function getCompatibility()
{
return self::hasCompatibility();
}
}

View File

@@ -0,0 +1,75 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Shared;
abstract class AbstractEnum
{
private static $constCacheArray = null;
private static function getConstants()
{
if (self::$constCacheArray == null) {
self::$constCacheArray = array();
}
$calledClass = get_called_class();
if (!array_key_exists($calledClass, self::$constCacheArray)) {
$reflect = new \ReflectionClass($calledClass);
self::$constCacheArray[$calledClass] = $reflect->getConstants();
}
return self::$constCacheArray[$calledClass];
}
/**
* Returns all values for this enum
*
* @return array
*/
public static function values()
{
return array_values(self::getConstants());
}
/**
* Returns true the value is valid for this enum
*
* @param string $value
* @return bool true if value is valid
*/
public static function isValid($value)
{
$values = array_values(self::getConstants());
return in_array($value, $values, true);
}
/**
* Validates that the value passed is a valid value
*
* @param string $value
* @throws \InvalidArgumentException if the value passed is not valid for this enum
*/
public static function validate($value)
{
if (!self::isValid($value)) {
$calledClass = get_called_class();
$values = array_values(self::getConstants());
throw new \InvalidArgumentException("$value is not a valid value for $calledClass, possible values are " . implode(', ', $values));
}
}
}

View File

@@ -0,0 +1,426 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Shared;
/**
* Common converter functions
*/
class Converter
{
const INCH_TO_CM = 2.54;
const INCH_TO_TWIP = 1440;
const INCH_TO_PIXEL = 96;
const INCH_TO_POINT = 72;
const INCH_TO_PICA = 6;
const PIXEL_TO_EMU = 9525;
const DEGREE_TO_ANGLE = 60000;
/**
* Convert centimeter to twip
*
* @param float $centimeter
* @return float
*/
public static function cmToTwip($centimeter = 1)
{
return $centimeter / self::INCH_TO_CM * self::INCH_TO_TWIP;
}
/**
* Convert centimeter to inch
*
* @param float $centimeter
* @return float
*/
public static function cmToInch($centimeter = 1)
{
return $centimeter / self::INCH_TO_CM;
}
/**
* Convert centimeter to pixel
*
* @param float $centimeter
* @return float
*/
public static function cmToPixel($centimeter = 1)
{
return $centimeter / self::INCH_TO_CM * self::INCH_TO_PIXEL;
}
/**
* Convert centimeter to point
*
* @param float $centimeter
* @return float
*/
public static function cmToPoint($centimeter = 1)
{
return $centimeter / self::INCH_TO_CM * self::INCH_TO_POINT;
}
/**
* Convert centimeter to EMU
*
* @param float $centimeter
* @return float
*/
public static function cmToEmu($centimeter = 1)
{
return round($centimeter / self::INCH_TO_CM * self::INCH_TO_PIXEL * self::PIXEL_TO_EMU);
}
/**
* Convert inch to twip
*
* @param float $inch
* @return float
*/
public static function inchToTwip($inch = 1)
{
return $inch * self::INCH_TO_TWIP;
}
/**
* Convert inch to centimeter
*
* @param float $inch
* @return float
*/
public static function inchToCm($inch = 1)
{
return $inch * self::INCH_TO_CM;
}
/**
* Convert inch to pixel
*
* @param float $inch
* @return float
*/
public static function inchToPixel($inch = 1)
{
return $inch * self::INCH_TO_PIXEL;
}
/**
* Convert inch to point
*
* @param float $inch
* @return float
*/
public static function inchToPoint($inch = 1)
{
return $inch * self::INCH_TO_POINT;
}
/**
* Convert inch to EMU
*
* @param float $inch
* @return int
*/
public static function inchToEmu($inch = 1)
{
return round($inch * self::INCH_TO_PIXEL * self::PIXEL_TO_EMU);
}
/**
* Convert pixel to twip
*
* @param float $pixel
* @return float
*/
public static function pixelToTwip($pixel = 1)
{
return $pixel / self::INCH_TO_PIXEL * self::INCH_TO_TWIP;
}
/**
* Convert pixel to centimeter
*
* @param float $pixel
* @return float
*/
public static function pixelToCm($pixel = 1)
{
return $pixel / self::INCH_TO_PIXEL * self::INCH_TO_CM;
}
/**
* Convert pixel to point
*
* @param float $pixel
* @return float
*/
public static function pixelToPoint($pixel = 1)
{
return $pixel / self::INCH_TO_PIXEL * self::INCH_TO_POINT;
}
/**
* Convert pixel to EMU
*
* @param float $pixel
* @return int
*/
public static function pixelToEmu($pixel = 1)
{
return round($pixel * self::PIXEL_TO_EMU);
}
/**
* Convert point to twip unit
*
* @param float $point
* @return float
*/
public static function pointToTwip($point = 1)
{
return $point / self::INCH_TO_POINT * self::INCH_TO_TWIP;
}
/**
* Convert point to pixel
*
* @param float $point
* @return float
*/
public static function pointToPixel($point = 1)
{
return $point / self::INCH_TO_POINT * self::INCH_TO_PIXEL;
}
/**
* Convert point to EMU
*
* @param float $point
* @return float
*/
public static function pointToEmu($point = 1)
{
return round($point / self::INCH_TO_POINT * self::INCH_TO_PIXEL * self::PIXEL_TO_EMU);
}
/**
* Convert point to cm
*
* @param float $point
* @return float
*/
public static function pointToCm($point = 1)
{
return $point / self::INCH_TO_POINT * self::INCH_TO_CM;
}
/**
* Convert EMU to pixel
*
* @param float $emu
* @return float
*/
public static function emuToPixel($emu = 1)
{
return round($emu / self::PIXEL_TO_EMU);
}
/**
* Convert pica to point
*
* @param float $pica
* @return float
*/
public static function picaToPoint($pica = 1)
{
return $pica / self::INCH_TO_PICA * self::INCH_TO_POINT;
}
/**
* Convert degree to angle
*
* @param float $degree
* @return int
*/
public static function degreeToAngle($degree = 1)
{
return (int) round($degree * self::DEGREE_TO_ANGLE);
}
/**
* Convert angle to degrees
*
* @param float $angle
* @return int
*/
public static function angleToDegree($angle = 1)
{
return round($angle / self::DEGREE_TO_ANGLE);
}
/**
* Convert colorname as string to RGB
*
* @param string $value color name
* @return string color as hex RGB string, or original value if unknown
*/
public static function stringToRgb($value)
{
switch ($value) {
case \PhpOffice\PhpWord\Style\Font::FGCOLOR_YELLOW:
return 'FFFF00';
case \PhpOffice\PhpWord\Style\Font::FGCOLOR_LIGHTGREEN:
return '90EE90';
case \PhpOffice\PhpWord\Style\Font::FGCOLOR_CYAN:
return '00FFFF';
case \PhpOffice\PhpWord\Style\Font::FGCOLOR_MAGENTA:
return 'FF00FF';
case \PhpOffice\PhpWord\Style\Font::FGCOLOR_BLUE:
return '0000FF';
case \PhpOffice\PhpWord\Style\Font::FGCOLOR_RED:
return 'FF0000';
case \PhpOffice\PhpWord\Style\Font::FGCOLOR_DARKBLUE:
return '00008B';
case \PhpOffice\PhpWord\Style\Font::FGCOLOR_DARKCYAN:
return '008B8B';
case \PhpOffice\PhpWord\Style\Font::FGCOLOR_DARKGREEN:
return '006400';
case \PhpOffice\PhpWord\Style\Font::FGCOLOR_DARKMAGENTA:
return '8B008B';
case \PhpOffice\PhpWord\Style\Font::FGCOLOR_DARKRED:
return '8B0000';
case \PhpOffice\PhpWord\Style\Font::FGCOLOR_DARKYELLOW:
return '8B8B00';
case \PhpOffice\PhpWord\Style\Font::FGCOLOR_DARKGRAY:
return 'A9A9A9';
case \PhpOffice\PhpWord\Style\Font::FGCOLOR_LIGHTGRAY:
return 'D3D3D3';
case \PhpOffice\PhpWord\Style\Font::FGCOLOR_BLACK:
return '000000';
}
return $value;
}
/**
* Convert HTML hexadecimal to RGB
*
* @param string $value HTML Color in hexadecimal
* @return array Value in RGB
*/
public static function htmlToRgb($value)
{
if ($value[0] == '#') {
$value = substr($value, 1);
} else {
$value = self::stringToRgb($value);
}
if (strlen($value) == 6) {
list($red, $green, $blue) = array($value[0] . $value[1], $value[2] . $value[3], $value[4] . $value[5]);
} elseif (strlen($value) == 3) {
list($red, $green, $blue) = array($value[0] . $value[0], $value[1] . $value[1], $value[2] . $value[2]);
} else {
return false;
}
$red = ctype_xdigit($red) ? hexdec($red) : 0;
$green = ctype_xdigit($green) ? hexdec($green) : 0;
$blue = ctype_xdigit($blue) ? hexdec($blue) : 0;
return array($red, $green, $blue);
}
/**
* Transforms a size in CSS format (eg. 10px, 10px, ...) to points
*
* @param string $value
* @return float
*/
public static function cssToPoint($value)
{
if ($value == '0') {
return 0;
}
$matches = array();
if (preg_match('/^[+-]?([0-9]+\.?[0-9]*)?(px|em|ex|%|in|cm|mm|pt|pc)$/i', $value, $matches)) {
$size = $matches[1];
$unit = $matches[2];
switch ($unit) {
case 'pt':
return $size;
case 'px':
return self::pixelToPoint($size);
case 'cm':
return self::cmToPoint($size);
case 'mm':
return self::cmToPoint($size / 10);
case 'in':
return self::inchToPoint($size);
case 'pc':
return self::picaToPoint($size);
}
}
return null;
}
/**
* Transforms a size in CSS format (eg. 10px, 10px, ...) to twips
*
* @param string $value
* @return float
*/
public static function cssToTwip($value)
{
return self::pointToTwip(self::cssToPoint($value));
}
/**
* Transforms a size in CSS format (eg. 10px, 10px, ...) to pixel
*
* @param string $value
* @return float
*/
public static function cssToPixel($value)
{
return self::pointToPixel(self::cssToPoint($value));
}
/**
* Transforms a size in CSS format (eg. 10px, 10px, ...) to cm
*
* @param string $value
* @return float
*/
public static function cssToCm($value)
{
return self::pointToCm(self::cssToPoint($value));
}
/**
* Transforms a size in CSS format (eg. 10px, 10px, ...) to emu
*
* @param string $value
* @return float
*/
public static function cssToEmu($value)
{
return self::pointToEmu(self::cssToPoint($value));
}
}

View File

@@ -0,0 +1,248 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Shared;
/**
* Drawing
*/
class Drawing
{
const DPI_96 = 96;
/**
* Convert pixels to EMU
*
* @param int $pValue Value in pixels
* @return int
*/
public static function pixelsToEmu($pValue = 0)
{
return round($pValue * 9525);
}
/**
* Convert EMU to pixels
*
* @param int $pValue Value in EMU
* @return int
*/
public static function emuToPixels($pValue = 0)
{
if ($pValue == 0) {
return 0;
}
return round($pValue / 9525);
}
/**
* Convert pixels to points
*
* @param int $pValue Value in pixels
* @return float
*/
public static function pixelsToPoints($pValue = 0)
{
return $pValue * 0.67777777;
}
/**
* Convert points width to centimeters
*
* @param int $pValue Value in points
* @return float
*/
public static function pointsToCentimeters($pValue = 0)
{
if ($pValue == 0) {
return 0;
}
return (($pValue * 1.333333333) / self::DPI_96) * 2.54;
}
/**
* Convert points width to pixels
*
* @param int $pValue Value in points
* @return float
*/
public static function pointsToPixels($pValue = 0)
{
if ($pValue == 0) {
return 0;
}
return $pValue * 1.333333333;
}
/**
* Convert pixels to centimeters
*
* @param int $pValue Value in pixels
* @return float
*/
public static function pixelsToCentimeters($pValue = 0)
{
//return $pValue * 0.028;
return ($pValue / self::DPI_96) * 2.54;
}
/**
* Convert centimeters width to pixels
*
* @param int $pValue Value in centimeters
* @return float
*/
public static function centimetersToPixels($pValue = 0)
{
if ($pValue == 0) {
return 0;
}
return ($pValue / 2.54) * self::DPI_96;
}
/**
* Convert degrees to angle
*
* @param int $pValue Degrees
* @return int
*/
public static function degreesToAngle($pValue = 0)
{
return (int) round($pValue * 60000);
}
/**
* Convert angle to degrees
*
* @param int $pValue Angle
* @return int
*/
public static function angleToDegrees($pValue = 0)
{
if ($pValue == 0) {
return 0;
}
return round($pValue / 60000);
}
/**
* Convert centimeters width to twips
*
* @param int $pValue
* @return float
*/
public static function centimetersToTwips($pValue = 0)
{
if ($pValue == 0) {
return 0;
}
return $pValue * 566.928;
}
/**
* Convert twips width to centimeters
*
* @param int $pValue
* @return float
*/
public static function twipsToCentimeters($pValue = 0)
{
if ($pValue == 0) {
return 0;
}
return $pValue / 566.928;
}
/**
* Convert inches width to twips
*
* @param int $pValue
* @return float
*/
public static function inchesToTwips($pValue = 0)
{
if ($pValue == 0) {
return 0;
}
return $pValue * 1440;
}
/**
* Convert twips width to inches
*
* @param int $pValue
* @return float
*/
public static function twipsToInches($pValue = 0)
{
if ($pValue == 0) {
return 0;
}
return $pValue / 1440;
}
/**
* Convert twips width to pixels
*
* @param int $pValue
* @return float
*/
public static function twipsToPixels($pValue = 0)
{
if ($pValue == 0) {
return 0;
}
return round($pValue / 15.873984);
}
/**
* Convert HTML hexadecimal to RGB
*
* @param string $pValue HTML Color in hexadecimal
* @return array|false Value in RGB
*/
public static function htmlToRGB($pValue)
{
if ($pValue[0] == '#') {
$pValue = substr($pValue, 1);
}
if (strlen($pValue) == 6) {
list($colorR, $colorG, $colorB) = array($pValue[0] . $pValue[1], $pValue[2] . $pValue[3], $pValue[4] . $pValue[5]);
} elseif (strlen($pValue) == 3) {
list($colorR, $colorG, $colorB) = array($pValue[0] . $pValue[0], $pValue[1] . $pValue[1], $pValue[2] . $pValue[2]);
} else {
return false;
}
$colorR = hexdec($colorR);
$colorG = hexdec($colorG);
$colorB = hexdec($colorB);
return array($colorR, $colorG, $colorB);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,235 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Shared\Microsoft;
/**
* Password encoder for microsoft office applications
*/
class PasswordEncoder
{
const ALGORITHM_MD2 = 'MD2';
const ALGORITHM_MD4 = 'MD4';
const ALGORITHM_MD5 = 'MD5';
const ALGORITHM_SHA_1 = 'SHA-1';
const ALGORITHM_SHA_256 = 'SHA-256';
const ALGORITHM_SHA_384 = 'SHA-384';
const ALGORITHM_SHA_512 = 'SHA-512';
const ALGORITHM_RIPEMD = 'RIPEMD';
const ALGORITHM_RIPEMD_160 = 'RIPEMD-160';
const ALGORITHM_MAC = 'MAC';
const ALGORITHM_HMAC = 'HMAC';
/**
* Mapping between algorithm name and algorithm ID
*
* @var array
* @see https://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.writeprotection.cryptographicalgorithmsid(v=office.14).aspx
*/
private static $algorithmMapping = array(
self::ALGORITHM_MD2 => array(1, 'md2'),
self::ALGORITHM_MD4 => array(2, 'md4'),
self::ALGORITHM_MD5 => array(3, 'md5'),
self::ALGORITHM_SHA_1 => array(4, 'sha1'),
self::ALGORITHM_MAC => array(5, ''), // 'mac' -> not possible with hash()
self::ALGORITHM_RIPEMD => array(6, 'ripemd'),
self::ALGORITHM_RIPEMD_160 => array(7, 'ripemd160'),
self::ALGORITHM_HMAC => array(9, ''), //'hmac' -> not possible with hash()
self::ALGORITHM_SHA_256 => array(12, 'sha256'),
self::ALGORITHM_SHA_384 => array(13, 'sha384'),
self::ALGORITHM_SHA_512 => array(14, 'sha512'),
);
private static $initialCodeArray = array(
0xE1F0,
0x1D0F,
0xCC9C,
0x84C0,
0x110C,
0x0E10,
0xF1CE,
0x313E,
0x1872,
0xE139,
0xD40F,
0x84F9,
0x280C,
0xA96A,
0x4EC3,
);
private static $encryptionMatrix = array(
array(0xAEFC, 0x4DD9, 0x9BB2, 0x2745, 0x4E8A, 0x9D14, 0x2A09),
array(0x7B61, 0xF6C2, 0xFDA5, 0xEB6B, 0xC6F7, 0x9DCF, 0x2BBF),
array(0x4563, 0x8AC6, 0x05AD, 0x0B5A, 0x16B4, 0x2D68, 0x5AD0),
array(0x0375, 0x06EA, 0x0DD4, 0x1BA8, 0x3750, 0x6EA0, 0xDD40),
array(0xD849, 0xA0B3, 0x5147, 0xA28E, 0x553D, 0xAA7A, 0x44D5),
array(0x6F45, 0xDE8A, 0xAD35, 0x4A4B, 0x9496, 0x390D, 0x721A),
array(0xEB23, 0xC667, 0x9CEF, 0x29FF, 0x53FE, 0xA7FC, 0x5FD9),
array(0x47D3, 0x8FA6, 0x0F6D, 0x1EDA, 0x3DB4, 0x7B68, 0xF6D0),
array(0xB861, 0x60E3, 0xC1C6, 0x93AD, 0x377B, 0x6EF6, 0xDDEC),
array(0x45A0, 0x8B40, 0x06A1, 0x0D42, 0x1A84, 0x3508, 0x6A10),
array(0xAA51, 0x4483, 0x8906, 0x022D, 0x045A, 0x08B4, 0x1168),
array(0x76B4, 0xED68, 0xCAF1, 0x85C3, 0x1BA7, 0x374E, 0x6E9C),
array(0x3730, 0x6E60, 0xDCC0, 0xA9A1, 0x4363, 0x86C6, 0x1DAD),
array(0x3331, 0x6662, 0xCCC4, 0x89A9, 0x0373, 0x06E6, 0x0DCC),
array(0x1021, 0x2042, 0x4084, 0x8108, 0x1231, 0x2462, 0x48C4),
);
private static $passwordMaxLength = 15;
/**
* Create a hashed password that MS Word will be able to work with
* @see https://blogs.msdn.microsoft.com/vsod/2010/04/05/how-to-set-the-editing-restrictions-in-word-using-open-xml-sdk-2-0/
*
* @param string $password
* @param string $algorithmName
* @param string $salt
* @param int $spinCount
* @return string
*/
public static function hashPassword($password, $algorithmName = self::ALGORITHM_SHA_1, $salt = null, $spinCount = 10000)
{
$origEncoding = mb_internal_encoding();
mb_internal_encoding('UTF-8');
$password = mb_substr($password, 0, min(self::$passwordMaxLength, mb_strlen($password)));
// Get the single-byte values by iterating through the Unicode characters of the truncated password.
// For each character, if the low byte is not equal to 0, take it. Otherwise, take the high byte.
$passUtf8 = mb_convert_encoding($password, 'UCS-2LE', 'UTF-8');
$byteChars = array();
for ($i = 0; $i < mb_strlen($password); $i++) {
$byteChars[$i] = ord(substr($passUtf8, $i * 2, 1));
if ($byteChars[$i] == 0) {
$byteChars[$i] = ord(substr($passUtf8, $i * 2 + 1, 1));
}
}
// build low-order word and hig-order word and combine them
$combinedKey = self::buildCombinedKey($byteChars);
// build reversed hexadecimal string
$hex = str_pad(strtoupper(dechex($combinedKey & 0xFFFFFFFF)), 8, '0', \STR_PAD_LEFT);
$reversedHex = $hex[6] . $hex[7] . $hex[4] . $hex[5] . $hex[2] . $hex[3] . $hex[0] . $hex[1];
$generatedKey = mb_convert_encoding($reversedHex, 'UCS-2LE', 'UTF-8');
// Implementation Notes List:
// Word requires that the initial hash of the password with the salt not be considered in the count.
// The initial hash of salt + key is not included in the iteration count.
$algorithm = self::getAlgorithm($algorithmName);
$generatedKey = hash($algorithm, $salt . $generatedKey, true);
for ($i = 0; $i < $spinCount; $i++) {
$generatedKey = hash($algorithm, $generatedKey . pack('CCCC', $i, $i >> 8, $i >> 16, $i >> 24), true);
}
$generatedKey = base64_encode($generatedKey);
mb_internal_encoding($origEncoding);
return $generatedKey;
}
/**
* Get algorithm from self::$algorithmMapping
*
* @param string $algorithmName
* @return string
*/
private static function getAlgorithm($algorithmName)
{
$algorithm = self::$algorithmMapping[$algorithmName][1];
if ($algorithm == '') {
$algorithm = 'sha1';
}
return $algorithm;
}
/**
* Returns the algorithm ID
*
* @param string $algorithmName
* @return int
*/
public static function getAlgorithmId($algorithmName)
{
return self::$algorithmMapping[$algorithmName][0];
}
/**
* Build combined key from low-order word and high-order word
*
* @param array $byteChars byte array representation of password
* @return int
*/
private static function buildCombinedKey($byteChars)
{
$byteCharsLength = count($byteChars);
// Compute the high-order word
// Initialize from the initial code array (see above), depending on the passwords length.
$highOrderWord = self::$initialCodeArray[$byteCharsLength - 1];
// For each character in the password:
// For every bit in the character, starting with the least significant and progressing to (but excluding)
// the most significant, if the bit is set, XOR the keys high-order word with the corresponding word from
// the Encryption Matrix
for ($i = 0; $i < $byteCharsLength; $i++) {
$tmp = self::$passwordMaxLength - $byteCharsLength + $i;
$matrixRow = self::$encryptionMatrix[$tmp];
for ($intBit = 0; $intBit < 7; $intBit++) {
if (($byteChars[$i] & (0x0001 << $intBit)) != 0) {
$highOrderWord = ($highOrderWord ^ $matrixRow[$intBit]);
}
}
}
// Compute low-order word
// Initialize with 0
$lowOrderWord = 0;
// For each character in the password, going backwards
for ($i = $byteCharsLength - 1; $i >= 0; $i--) {
// low-order word = (((low-order word SHR 14) AND 0x0001) OR (low-order word SHL 1) AND 0x7FFF)) XOR character
$lowOrderWord = (((($lowOrderWord >> 14) & 0x0001) | (($lowOrderWord << 1) & 0x7FFF)) ^ $byteChars[$i]);
}
// Lastly, low-order word = (((low-order word SHR 14) AND 0x0001) OR (low-order word SHL 1) AND 0x7FFF)) XOR strPassword length XOR 0xCE4B.
$lowOrderWord = (((($lowOrderWord >> 14) & 0x0001) | (($lowOrderWord << 1) & 0x7FFF)) ^ $byteCharsLength ^ 0xCE4B);
// Combine the Low and High Order Word
return self::int32(($highOrderWord << 16) + $lowOrderWord);
}
/**
* Simulate behaviour of (signed) int32
*
* @codeCoverageIgnore
* @param int $value
* @return int
*/
private static function int32($value)
{
$value = ($value & 0xFFFFFFFF);
if ($value & 0x80000000) {
$value = -((~$value & 0xFFFFFFFF) + 1);
}
return $value;
}
}

View File

@@ -0,0 +1,323 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Shared;
use PhpOffice\PhpWord\Exception\Exception;
defined('IDENTIFIER_OLE') ||
define('IDENTIFIER_OLE', pack('CCCCCCCC', 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1));
class OLERead
{
private $data = '';
// OLE identifier
const IDENTIFIER_OLE = IDENTIFIER_OLE;
// Size of a sector = 512 bytes
const BIG_BLOCK_SIZE = 0x200;
// Size of a short sector = 64 bytes
const SMALL_BLOCK_SIZE = 0x40;
// Size of a directory entry always = 128 bytes
const PROPERTY_STORAGE_BLOCK_SIZE = 0x80;
// Minimum size of a standard stream = 4096 bytes, streams smaller than this are stored as short streams
const SMALL_BLOCK_THRESHOLD = 0x1000;
// header offsets
const NUM_BIG_BLOCK_DEPOT_BLOCKS_POS = 0x2c;
const ROOT_START_BLOCK_POS = 0x30;
const SMALL_BLOCK_DEPOT_BLOCK_POS = 0x3c;
const EXTENSION_BLOCK_POS = 0x44;
const NUM_EXTENSION_BLOCK_POS = 0x48;
const BIG_BLOCK_DEPOT_BLOCKS_POS = 0x4c;
// property storage offsets (directory offsets)
const SIZE_OF_NAME_POS = 0x40;
const TYPE_POS = 0x42;
const START_BLOCK_POS = 0x74;
const SIZE_POS = 0x78;
public $wrkdocument = null;
public $wrk1Table = null;
public $wrkData = null;
public $wrkObjectPool = null;
public $summaryInformation = null;
public $docSummaryInfos = null;
/**
* Read the file
*
* @param $sFileName string Filename
*
* @throws Exception
*/
public function read($sFileName)
{
// Check if file exists and is readable
if (!is_readable($sFileName)) {
throw new Exception('Could not open ' . $sFileName . ' for reading! File does not exist, or it is not readable.');
}
// Get the file identifier
// Don't bother reading the whole file until we know it's a valid OLE file
$this->data = file_get_contents($sFileName, false, null, 0, 8);
// Check OLE identifier
if ($this->data != self::IDENTIFIER_OLE) {
throw new Exception('The filename ' . $sFileName . ' is not recognised as an OLE file');
}
// Get the file data
$this->data = file_get_contents($sFileName);
// Total number of sectors used for the SAT
$this->numBigBlockDepotBlocks = self::getInt4d($this->data, self::NUM_BIG_BLOCK_DEPOT_BLOCKS_POS);
// SecID of the first sector of the directory stream
$this->rootStartBlock = self::getInt4d($this->data, self::ROOT_START_BLOCK_POS);
// SecID of the first sector of the SSAT (or -2 if not extant)
$this->sbdStartBlock = self::getInt4d($this->data, self::SMALL_BLOCK_DEPOT_BLOCK_POS);
// SecID of the first sector of the MSAT (or -2 if no additional sectors are used)
$this->extensionBlock = self::getInt4d($this->data, self::EXTENSION_BLOCK_POS);
// Total number of sectors used by MSAT
$this->numExtensionBlocks = self::getInt4d($this->data, self::NUM_EXTENSION_BLOCK_POS);
$bigBlockDepotBlocks = array();
$pos = self::BIG_BLOCK_DEPOT_BLOCKS_POS;
$bbdBlocks = $this->numBigBlockDepotBlocks;
// @codeCoverageIgnoreStart
if ($this->numExtensionBlocks != 0) {
$bbdBlocks = (self::BIG_BLOCK_SIZE - self::BIG_BLOCK_DEPOT_BLOCKS_POS) / 4;
}
// @codeCoverageIgnoreEnd
for ($i = 0; $i < $bbdBlocks; ++$i) {
$bigBlockDepotBlocks[$i] = self::getInt4d($this->data, $pos);
$pos += 4;
}
// @codeCoverageIgnoreStart
for ($j = 0; $j < $this->numExtensionBlocks; ++$j) {
$pos = ($this->extensionBlock + 1) * self::BIG_BLOCK_SIZE;
$blocksToRead = min($this->numBigBlockDepotBlocks - $bbdBlocks, self::BIG_BLOCK_SIZE / 4 - 1);
for ($i = $bbdBlocks; $i < $bbdBlocks + $blocksToRead; ++$i) {
$bigBlockDepotBlocks[$i] = self::getInt4d($this->data, $pos);
$pos += 4;
}
$bbdBlocks += $blocksToRead;
if ($bbdBlocks < $this->numBigBlockDepotBlocks) {
$this->extensionBlock = self::getInt4d($this->data, $pos);
}
}
// @codeCoverageIgnoreEnd
$pos = 0;
$this->bigBlockChain = '';
$bbs = self::BIG_BLOCK_SIZE / 4;
for ($i = 0; $i < $this->numBigBlockDepotBlocks; ++$i) {
$pos = ($bigBlockDepotBlocks[$i] + 1) * self::BIG_BLOCK_SIZE;
$this->bigBlockChain .= substr($this->data, $pos, 4 * $bbs);
$pos += 4 * $bbs;
}
$pos = 0;
$sbdBlock = $this->sbdStartBlock;
$this->smallBlockChain = '';
while ($sbdBlock != -2) {
$pos = ($sbdBlock + 1) * self::BIG_BLOCK_SIZE;
$this->smallBlockChain .= substr($this->data, $pos, 4 * $bbs);
$pos += 4 * $bbs;
$sbdBlock = self::getInt4d($this->bigBlockChain, $sbdBlock * 4);
}
// read the directory stream
$block = $this->rootStartBlock;
$this->entry = $this->readData($block);
$this->readPropertySets();
}
/**
* Extract binary stream data
*
* @param mixed $stream
* @return string
*/
public function getStream($stream)
{
if ($stream === null) {
return null;
}
$streamData = '';
if ($this->props[$stream]['size'] < self::SMALL_BLOCK_THRESHOLD) {
$rootdata = $this->readData($this->props[$this->rootentry]['startBlock']);
$block = $this->props[$stream]['startBlock'];
while ($block != -2) {
$pos = $block * self::SMALL_BLOCK_SIZE;
$streamData .= substr($rootdata, $pos, self::SMALL_BLOCK_SIZE);
$block = self::getInt4d($this->smallBlockChain, $block * 4);
}
return $streamData;
}
$numBlocks = $this->props[$stream]['size'] / self::BIG_BLOCK_SIZE;
if ($this->props[$stream]['size'] % self::BIG_BLOCK_SIZE != 0) {
++$numBlocks;
}
if ($numBlocks == 0) {
return ''; // @codeCoverageIgnore
}
$block = $this->props[$stream]['startBlock'];
while ($block != -2) {
$pos = ($block + 1) * self::BIG_BLOCK_SIZE;
$streamData .= substr($this->data, $pos, self::BIG_BLOCK_SIZE);
$block = self::getInt4d($this->bigBlockChain, $block * 4);
}
return $streamData;
}
/**
* Read a standard stream (by joining sectors using information from SAT)
*
* @param int $blSectorId Sector ID where the stream starts
* @return string Data for standard stream
*/
private function readData($blSectorId)
{
$block = $blSectorId;
$data = '';
while ($block != -2) {
$pos = ($block + 1) * self::BIG_BLOCK_SIZE;
$data .= substr($this->data, $pos, self::BIG_BLOCK_SIZE);
$block = self::getInt4d($this->bigBlockChain, $block * 4);
}
return $data;
}
/**
* Read entries in the directory stream.
*/
private function readPropertySets()
{
$offset = 0;
// loop through entires, each entry is 128 bytes
$entryLen = strlen($this->entry);
while ($offset < $entryLen) {
// entry data (128 bytes)
$data = substr($this->entry, $offset, self::PROPERTY_STORAGE_BLOCK_SIZE);
// size in bytes of name
$nameSize = ord($data[self::SIZE_OF_NAME_POS]) | (ord($data[self::SIZE_OF_NAME_POS + 1]) << 8);
// type of entry
$type = ord($data[self::TYPE_POS]);
// sectorID of first sector or short sector, if this entry refers to a stream (the case with workbook)
// sectorID of first sector of the short-stream container stream, if this entry is root entry
$startBlock = self::getInt4d($data, self::START_BLOCK_POS);
$size = self::getInt4d($data, self::SIZE_POS);
$name = str_replace("\x00", '', substr($data, 0, $nameSize));
$this->props[] = array(
'name' => $name,
'type' => $type,
'startBlock' => $startBlock,
'size' => $size, );
// tmp helper to simplify checks
$upName = strtoupper($name);
// Workbook directory entry (BIFF5 uses Book, BIFF8 uses Workbook)
// print_r($upName.PHP_EOL);
if (($upName === 'WORDDOCUMENT')) {
$this->wrkdocument = count($this->props) - 1;
} elseif ($upName === '1TABLE') {
$this->wrk1Table = count($this->props) - 1;
} elseif ($upName === 'DATA') {
$this->wrkData = count($this->props) - 1;
} elseif ($upName === 'OBJECTPOOL') {
$this->wrkObjectPoolelseif = count($this->props) - 1;
} elseif ($upName === 'ROOT ENTRY' || $upName === 'R') {
$this->rootentry = count($this->props) - 1;
}
// Summary information
if ($name == chr(5) . 'SummaryInformation') {
$this->summaryInformation = count($this->props) - 1;
}
// Additional Document Summary information
if ($name == chr(5) . 'DocumentSummaryInformation') {
$this->docSummaryInfos = count($this->props) - 1;
}
$offset += self::PROPERTY_STORAGE_BLOCK_SIZE;
}
}
/**
* Read 4 bytes of data at specified position
*
* @param string $data
* @param int $pos
* @return int
*/
private static function getInt4d($data, $pos)
{
// FIX: represent numbers correctly on 64-bit system
// http://sourceforge.net/tracker/index.php?func=detail&aid=1487372&group_id=99160&atid=623334
// Hacked by Andreas Rehm 2006 to ensure correct result of the <<24 block on 32 and 64bit systems
$or24 = ord($data[$pos + 3]);
if ($or24 >= 128) {
// negative number
$ord24 = -abs((256 - $or24) << 24);
} else {
$ord24 = ($or24 & 127) << 24;
}
return ord($data[$pos]) | (ord($data[$pos + 1]) << 8) | (ord($data[$pos + 2]) << 16) | $ord24;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,236 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Shared;
/**
* Text
*/
class Text
{
/**
* Control characters array
*
* @var string[]
*/
private static $controlCharacters = array();
/**
* Build control characters array
*/
private static function buildControlCharacters()
{
for ($i = 0; $i <= 19; ++$i) {
if ($i != 9 && $i != 10 && $i != 13) {
$find = '_x' . sprintf('%04s', strtoupper(dechex($i))) . '_';
$replace = chr($i);
self::$controlCharacters[$find] = $replace;
}
}
}
/**
* Convert from PHP control character to OpenXML escaped control character
*
* Excel 2007 team:
* ----------------
* That's correct, control characters are stored directly in the shared-strings table.
* We do encode characters that cannot be represented in XML using the following escape sequence:
* _xHHHH_ where H represents a hexadecimal character in the character's value...
* So you could end up with something like _x0008_ in a string (either in a cell value (<v>)
* element or in the shared string <t> element.
*
* @param string $value Value to escape
* @return string
*/
public static function controlCharacterPHP2OOXML($value = '')
{
if (empty(self::$controlCharacters)) {
self::buildControlCharacters();
}
return str_replace(array_values(self::$controlCharacters), array_keys(self::$controlCharacters), $value);
}
/**
* Return a number formatted for being integrated in xml files
* @param float $number
* @param int $decimals
* @return string
*/
public static function numberFormat($number, $decimals)
{
return number_format($number, $decimals, '.', '');
}
/**
* @param int $dec
* @see http://stackoverflow.com/a/7153133/2235790
* @author velcrow
* @return string
*/
public static function chr($dec)
{
if ($dec <= 0x7F) {
return chr($dec);
}
if ($dec <= 0x7FF) {
return chr(($dec >> 6) + 192) . chr(($dec & 63) + 128);
}
if ($dec <= 0xFFFF) {
return chr(($dec >> 12) + 224) . chr((($dec >> 6) & 63) + 128) . chr(($dec & 63) + 128);
}
if ($dec <= 0x1FFFFF) {
return chr(($dec >> 18) + 240) . chr((($dec >> 12) & 63) + 128) . chr((($dec >> 6) & 63) + 128) . chr(($dec & 63) + 128);
}
return '';
}
/**
* Convert from OpenXML escaped control character to PHP control character
*
* @param string $value Value to unescape
* @return string
*/
public static function controlCharacterOOXML2PHP($value = '')
{
if (empty(self::$controlCharacters)) {
self::buildControlCharacters();
}
return str_replace(array_keys(self::$controlCharacters), array_values(self::$controlCharacters), $value);
}
/**
* Check if a string contains UTF-8 data
*
* @param string $value
* @return bool
*/
public static function isUTF8($value = '')
{
return is_string($value) && ($value === '' || preg_match('/^./su', $value) == 1);
}
/**
* Return UTF8 encoded value
*
* @param string $value
* @return string
*/
public static function toUTF8($value = '')
{
if (!is_null($value) && !self::isUTF8($value)) {
$value = utf8_encode($value);
}
return $value;
}
/**
* Returns unicode from UTF8 text
*
* The function is splitted to reduce cyclomatic complexity
*
* @param string $text UTF8 text
* @return string Unicode text
* @since 0.11.0
*/
public static function toUnicode($text)
{
return self::unicodeToEntities(self::utf8ToUnicode($text));
}
/**
* Returns unicode array from UTF8 text
*
* @param string $text UTF8 text
* @return array
* @since 0.11.0
* @see http://www.randomchaos.com/documents/?source=php_and_unicode
*/
public static function utf8ToUnicode($text)
{
$unicode = array();
$values = array();
$lookingFor = 1;
// Gets unicode for each character
for ($i = 0; $i < strlen($text); $i++) {
$thisValue = ord($text[$i]);
if ($thisValue < 128) {
$unicode[] = $thisValue;
} else {
if (count($values) == 0) {
$lookingFor = $thisValue < 224 ? 2 : 3;
}
$values[] = $thisValue;
if (count($values) == $lookingFor) {
if ($lookingFor == 3) {
$number = (($values[0] % 16) * 4096) + (($values[1] % 64) * 64) + ($values[2] % 64);
} else {
$number = (($values[0] % 32) * 64) + ($values[1] % 64);
}
$unicode[] = $number;
$values = array();
$lookingFor = 1;
}
}
}
return $unicode;
}
/**
* Returns entites from unicode array
*
* @param array $unicode
* @return string
* @since 0.11.0
* @see http://www.randomchaos.com/documents/?source=php_and_unicode
*/
private static function unicodeToEntities($unicode)
{
$entities = '';
foreach ($unicode as $value) {
if ($value != 65279) {
$entities .= $value > 127 ? '\uc0{\u' . $value . '}' : chr($value);
}
}
return $entities;
}
/**
* Return name without underscore for < 0.10.0 variable name compatibility
*
* @param string $value
* @return string
*/
public static function removeUnderscorePrefix($value)
{
if (!is_null($value)) {
if (substr($value, 0, 1) == '_') {
$value = substr($value, 1);
}
}
return $value;
}
}

View File

@@ -0,0 +1,216 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Shared;
/**
* XML Reader wrapper
*
* @since 0.2.1
*/
class XMLReader
{
/**
* DOMDocument object
*
* @var \DOMDocument
*/
private $dom = null;
/**
* DOMXpath object
*
* @var \DOMXpath
*/
private $xpath = null;
/**
* Get DOMDocument from ZipArchive
*
* @param string $zipFile
* @param string $xmlFile
* @throws \Exception
* @return \DOMDocument|false
*/
public function getDomFromZip($zipFile, $xmlFile)
{
if (file_exists($zipFile) === false) {
throw new \Exception('Cannot find archive file.');
}
$zip = new \ZipArchive();
$zip->open($zipFile);
$content = $zip->getFromName($xmlFile);
$zip->close();
if ($content === false) {
return false;
}
return $this->getDomFromString($content);
}
/**
* Get DOMDocument from content string
*
* @param string $content
* @return \DOMDocument
*/
public function getDomFromString($content)
{
if (\PHP_VERSION_ID < 80000) {
$originalLibXMLEntityValue = libxml_disable_entity_loader(true);
}
$this->dom = new \DOMDocument();
$this->dom->loadXML($content);
if (\PHP_VERSION_ID < 80000) {
libxml_disable_entity_loader($originalLibXMLEntityValue);
}
return $this->dom;
}
/**
* Get elements
*
* @param string $path
* @param \DOMElement $contextNode
* @return \DOMNodeList
*/
public function getElements($path, \DOMElement $contextNode = null)
{
if ($this->dom === null) {
return array();
}
if ($this->xpath === null) {
$this->xpath = new \DOMXpath($this->dom);
}
if (is_null($contextNode)) {
return $this->xpath->query($path);
}
return $this->xpath->query($path, $contextNode);
}
/**
* Registers the namespace with the DOMXPath object
*
* @param string $prefix The prefix
* @param string $namespaceURI The URI of the namespace
* @throws \InvalidArgumentException If called before having loaded the DOM document
* @return bool true on success or false on failure
*/
public function registerNamespace($prefix, $namespaceURI)
{
if ($this->dom === null) {
throw new \InvalidArgumentException('Dom needs to be loaded before registering a namespace');
}
if ($this->xpath === null) {
$this->xpath = new \DOMXpath($this->dom);
}
return $this->xpath->registerNamespace($prefix, $namespaceURI);
}
/**
* Get element
*
* @param string $path
* @param \DOMElement $contextNode
* @return \DOMElement|null
*/
public function getElement($path, \DOMElement $contextNode = null)
{
$elements = $this->getElements($path, $contextNode);
if ($elements->length > 0) {
return $elements->item(0);
}
return null;
}
/**
* Get element attribute
*
* @param string $attribute
* @param \DOMElement $contextNode
* @param string $path
* @return string|null
*/
public function getAttribute($attribute, \DOMElement $contextNode = null, $path = null)
{
$return = null;
if ($path !== null) {
$elements = $this->getElements($path, $contextNode);
if ($elements->length > 0) {
/** @var \DOMElement $node Type hint */
$node = $elements->item(0);
$return = $node->getAttribute($attribute);
}
} else {
if ($contextNode !== null) {
$return = $contextNode->getAttribute($attribute);
}
}
return ($return == '') ? null : $return;
}
/**
* Get element value
*
* @param string $path
* @param \DOMElement $contextNode
* @return string|null
*/
public function getValue($path, \DOMElement $contextNode = null)
{
$elements = $this->getElements($path, $contextNode);
if ($elements->length > 0) {
return $elements->item(0)->nodeValue;
}
return null;
}
/**
* Count elements
*
* @param string $path
* @param \DOMElement $contextNode
* @return int
*/
public function countElements($path, \DOMElement $contextNode = null)
{
$elements = $this->getElements($path, $contextNode);
return $elements->length;
}
/**
* Element exists
*
* @param string $path
* @param \DOMElement $contextNode
* @return bool
*/
public function elementExists($path, \DOMElement $contextNode = null)
{
return $this->getElements($path, $contextNode)->length > 0;
}
}

View File

@@ -0,0 +1,182 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Shared;
/**
* XMLWriter
*
* @method bool endElement()
* @method mixed flush(bool $empty = null)
* @method bool openMemory()
* @method string outputMemory(bool $flush = null)
* @method bool setIndent(bool $indent)
* @method bool startDocument(string $version = 1.0, string $encoding = null, string $standalone = null)
* @method bool startElement(string $name)
* @method bool text(string $content)
* @method bool writeCData(string $content)
* @method bool writeComment(string $content)
* @method bool writeElement(string $name, string $content = null)
* @method bool writeRaw(string $content)
*/
class XMLWriter extends \XMLWriter
{
/** Temporary storage method */
const STORAGE_MEMORY = 1;
const STORAGE_DISK = 2;
/**
* Temporary filename
*
* @var string
*/
private $tempFileName = '';
/**
* Create a new \PhpOffice\PhpWord\Shared\XMLWriter instance
*
* @param int $pTemporaryStorage Temporary storage location
* @param string $pTemporaryStorageDir Temporary storage folder
* @param bool $compatibility
*/
public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageDir = null, $compatibility = false)
{
// Open temporary storage
if ($pTemporaryStorage == self::STORAGE_MEMORY) {
$this->openMemory();
} else {
if (!is_dir($pTemporaryStorageDir)) {
$pTemporaryStorageDir = sys_get_temp_dir();
}
// Create temporary filename
$this->tempFileName = @tempnam($pTemporaryStorageDir, 'xml');
// Open storage
$this->openUri($this->tempFileName);
}
if ($compatibility) {
$this->setIndent(false);
$this->setIndentString('');
} else {
$this->setIndent(true);
$this->setIndentString(' ');
}
}
/**
* Destructor
*/
public function __destruct()
{
// Unlink temporary files
if (empty($this->tempFileName)) {
return;
}
if (PHP_OS != 'WINNT' && @unlink($this->tempFileName) === false) {
throw new \Exception('The file ' . $this->tempFileName . ' could not be deleted.');
}
}
/**
* Get written data
*
* @return string
*/
public function getData()
{
if ($this->tempFileName == '') {
return $this->outputMemory(true);
}
$this->flush();
return file_get_contents($this->tempFileName);
}
/**
* Write simple element and attribute(s) block
*
* There are two options:
* 1. If the `$attributes` is an array, then it's an associative array of attributes
* 2. If not, then it's a simple attribute-value pair
*
* @param string $element
* @param string|array $attributes
* @param string $value
*/
public function writeElementBlock($element, $attributes, $value = null)
{
$this->startElement($element);
if (!is_array($attributes)) {
$attributes = array($attributes => $value);
}
foreach ($attributes as $attribute => $value) {
$this->writeAttribute($attribute, $value);
}
$this->endElement();
}
/**
* Write element if ...
*
* @param bool $condition
* @param string $element
* @param string $attribute
* @param mixed $value
*/
public function writeElementIf($condition, $element, $attribute = null, $value = null)
{
if ($condition == true) {
if (is_null($attribute)) {
$this->writeElement($element, $value);
} else {
$this->startElement($element);
$this->writeAttribute($attribute, $value);
$this->endElement();
}
}
}
/**
* Write attribute if ...
*
* @param bool $condition
* @param string $attribute
* @param mixed $value
*/
public function writeAttributeIf($condition, $attribute, $value)
{
if ($condition == true) {
$this->writeAttribute($attribute, $value);
}
}
/**
* @param string $name
* @param mixed $value
* @return bool
*/
public function writeAttribute($name, $value)
{
if (is_float($value)) {
$value = json_encode($value);
}
return parent::writeAttribute($name, $value);
}
}

View File

@@ -0,0 +1,406 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Shared;
use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\Settings;
/**
* ZipArchive wrapper
*
* Wraps zip archive functionality of PHP ZipArchive and PCLZip. PHP ZipArchive
* properties and methods are bypassed and used as the model for the PCLZip
* emulation. Only needed PHP ZipArchive features are implemented.
*
* @method bool addFile(string $filename, string $localname = null)
* @method bool addFromString(string $localname, string $contents)
* @method string getNameIndex(int $index)
* @method int locateName(string $name)
*
* @since 0.10.0
*/
class ZipArchive
{
/** @const int Flags for open method */
const CREATE = 1; // Emulate \ZipArchive::CREATE
const OVERWRITE = 8; // Emulate \ZipArchive::OVERWRITE
/**
* Number of files (emulate ZipArchive::$numFiles)
*
* @var int
*/
public $numFiles = 0;
/**
* Archive filename (emulate ZipArchive::$filename)
*
* @var string
*/
public $filename;
/**
* Temporary storage directory
*
* @var string
*/
private $tempDir;
/**
* Internal zip archive object
*
* @var \ZipArchive|\PclZip
*/
private $zip;
/**
* Use PCLZip (default behaviour)
*
* @var bool
*/
private $usePclzip = true;
/**
* Create new instance
*/
public function __construct()
{
$this->usePclzip = (Settings::getZipClass() != 'ZipArchive');
if ($this->usePclzip) {
if (!defined('PCLZIP_TEMPORARY_DIR')) {
define('PCLZIP_TEMPORARY_DIR', Settings::getTempDir() . '/');
}
require_once 'PCLZip/pclzip.lib.php';
}
}
/**
* Catch function calls: pass to ZipArchive or PCLZip
*
* `call_user_func_array` can only used for public function, hence the `public` in all `pcl...` methods
*
* @param mixed $function
* @param mixed $args
* @return mixed
*/
public function __call($function, $args)
{
// Set object and function
$zipFunction = $function;
if (!$this->usePclzip) {
$zipObject = $this->zip;
} else {
$zipObject = $this;
$zipFunction = "pclzip{$zipFunction}";
}
// Run function
$result = false;
if (method_exists($zipObject, $zipFunction)) {
$result = @call_user_func_array(array($zipObject, $zipFunction), $args);
}
return $result;
}
/**
* Open a new zip archive
*
* @param string $filename The file name of the ZIP archive to open
* @param int $flags The mode to use to open the archive
* @return bool
*/
public function open($filename, $flags = null)
{
$result = true;
$this->filename = $filename;
$this->tempDir = Settings::getTempDir();
if (!$this->usePclzip) {
$zip = new \ZipArchive();
// PHP 8.1 compat - passing null as second arg to \ZipArchive::open() is deprecated
// passing 0 achieves the same behaviour
if ($flags === null) {
$flags = 0;
}
$result = $zip->open($this->filename, $flags);
// Scrutizer will report the property numFiles does not exist
// See https://github.com/scrutinizer-ci/php-analyzer/issues/190
$this->numFiles = $zip->numFiles;
} else {
$zip = new \PclZip($this->filename);
$zipContent = $zip->listContent();
$this->numFiles = is_array($zipContent) ? count($zipContent) : 0;
}
$this->zip = $zip;
return $result;
}
/**
* Close the active archive
*
* @throws \PhpOffice\PhpWord\Exception\Exception
*
* @return bool
*
* @codeCoverageIgnore Can't find any test case. Uncomment when found.
*/
public function close()
{
if (!$this->usePclzip) {
if ($this->zip->close() === false) {
throw new Exception("Could not close zip file {$this->filename}: ");
}
}
return true;
}
/**
* Extract the archive contents (emulate \ZipArchive)
*
* @param string $destination
* @param string|array $entries
* @return bool
* @since 0.10.0
*/
public function extractTo($destination, $entries = null)
{
if (!is_dir($destination)) {
return false;
}
if (!$this->usePclzip) {
return $this->zip->extractTo($destination, $entries);
}
return $this->pclzipExtractTo($destination, $entries);
}
/**
* Extract file from archive by given file name (emulate \ZipArchive)
*
* @param string $filename Filename for the file in zip archive
* @return string $contents File string contents
*/
public function getFromName($filename)
{
if (!$this->usePclzip) {
$contents = $this->zip->getFromName($filename);
if ($contents === false) {
$filename = substr($filename, 1);
$contents = $this->zip->getFromName($filename);
}
} else {
$contents = $this->pclzipGetFromName($filename);
}
return $contents;
}
/**
* Add a new file to the zip archive (emulate \ZipArchive)
*
* @param string $filename Directory/Name of the file to add to the zip archive
* @param string $localname Directory/Name of the file added to the zip
* @return bool
*/
public function pclzipAddFile($filename, $localname = null)
{
/** @var \PclZip $zip Type hint */
$zip = $this->zip;
// Bugfix GH-261 https://github.com/PHPOffice/PHPWord/pull/261
$realpathFilename = realpath($filename);
if ($realpathFilename !== false) {
$filename = $realpathFilename;
}
$filenameParts = pathinfo($filename);
$localnameParts = pathinfo($localname);
// To Rename the file while adding it to the zip we
// need to create a temp file with the correct name
$tempFile = false;
if ($filenameParts['basename'] != $localnameParts['basename']) {
$tempFile = true; // temp file created
$temppath = $this->tempDir . DIRECTORY_SEPARATOR . $localnameParts['basename'];
copy($filename, $temppath);
$filename = $temppath;
$filenameParts = pathinfo($temppath);
}
$pathRemoved = $filenameParts['dirname'];
$pathAdded = $localnameParts['dirname'];
if (!$this->usePclzip) {
$pathAdded = $pathAdded . '/' . ltrim(str_replace('\\', '/', substr($filename, strlen($pathRemoved))), '/');
//$res = $zip->addFile($filename, $pathAdded);
$res = $zip->addFromString($pathAdded, file_get_contents($filename)); // addFile can't use subfolders in some cases
} else {
$res = $zip->add($filename, PCLZIP_OPT_REMOVE_PATH, $pathRemoved, PCLZIP_OPT_ADD_PATH, $pathAdded);
}
if ($tempFile) {
// Remove temp file, if created
unlink($this->tempDir . DIRECTORY_SEPARATOR . $localnameParts['basename']);
}
return $res != 0;
}
/**
* Add a new file to the zip archive from a string of raw data (emulate \ZipArchive)
*
* @param string $localname Directory/Name of the file to add to the zip archive
* @param string $contents String of data to add to the zip archive
* @return bool
*/
public function pclzipAddFromString($localname, $contents)
{
/** @var \PclZip $zip Type hint */
$zip = $this->zip;
$filenameParts = pathinfo($localname);
// Write $contents to a temp file
$handle = fopen($this->tempDir . DIRECTORY_SEPARATOR . $filenameParts['basename'], 'wb');
fwrite($handle, $contents);
fclose($handle);
// Add temp file to zip
$filename = $this->tempDir . DIRECTORY_SEPARATOR . $filenameParts['basename'];
$pathRemoved = $this->tempDir;
$pathAdded = $filenameParts['dirname'];
$res = $zip->add($filename, PCLZIP_OPT_REMOVE_PATH, $pathRemoved, PCLZIP_OPT_ADD_PATH, $pathAdded);
// Remove temp file
@unlink($this->tempDir . DIRECTORY_SEPARATOR . $filenameParts['basename']);
return $res != 0;
}
/**
* Extract the archive contents (emulate \ZipArchive)
*
* @param string $destination
* @param string|array $entries
* @return bool
* @since 0.10.0
*/
public function pclzipExtractTo($destination, $entries = null)
{
/** @var \PclZip $zip Type hint */
$zip = $this->zip;
// Extract all files
if (is_null($entries)) {
$result = $zip->extract(PCLZIP_OPT_PATH, $destination);
return $result > 0;
}
// Extract by entries
if (!is_array($entries)) {
$entries = array($entries);
}
foreach ($entries as $entry) {
$entryIndex = $this->locateName($entry);
$result = $zip->extractByIndex($entryIndex, PCLZIP_OPT_PATH, $destination);
if ($result <= 0) {
return false;
}
}
return true;
}
/**
* Extract file from archive by given file name (emulate \ZipArchive)
*
* @param string $filename Filename for the file in zip archive
* @return string $contents File string contents
*/
public function pclzipGetFromName($filename)
{
/** @var \PclZip $zip Type hint */
$zip = $this->zip;
$listIndex = $this->pclzipLocateName($filename);
$contents = false;
if ($listIndex !== false) {
$extracted = $zip->extractByIndex($listIndex, PCLZIP_OPT_EXTRACT_AS_STRING);
} else {
$filename = substr($filename, 1);
$listIndex = $this->pclzipLocateName($filename);
$extracted = $zip->extractByIndex($listIndex, PCLZIP_OPT_EXTRACT_AS_STRING);
}
if ((is_array($extracted)) && ($extracted != 0)) {
$contents = $extracted[0]['content'];
}
return $contents;
}
/**
* Returns the name of an entry using its index (emulate \ZipArchive)
*
* @param int $index
* @return string|bool
* @since 0.10.0
*/
public function pclzipGetNameIndex($index)
{
/** @var \PclZip $zip Type hint */
$zip = $this->zip;
$list = $zip->listContent();
if (isset($list[$index])) {
return $list[$index]['filename'];
}
return false;
}
/**
* Returns the index of the entry in the archive (emulate \ZipArchive)
*
* @param string $filename Filename for the file in zip archive
* @return int
*/
public function pclzipLocateName($filename)
{
/** @var \PclZip $zip Type hint */
$zip = $this->zip;
$list = $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)) {
$listIndex = $i;
break;
}
}
return ($listIndex > -1) ? $listIndex : false;
}
}

View File

@@ -0,0 +1,58 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\SimpleType;
use PhpOffice\PhpWord\Shared\AbstractEnum;
/**
* Border Styles.
*
* @since 0.18.0
*
* @see http://www.datypic.com/sc/ooxml/t-w_ST_Border.html
*/
final class Border extends AbstractEnum
{
const SINGLE = 'single'; //A single line
const DASH_DOT_STROKED = 'dashDotStroked'; //A line with a series of alternating thin and thick strokes
const DASHED = 'dashed'; //A dashed line
const DASH_SMALL_GAP = 'dashSmallGap'; //A dashed line with small gaps
const DOT_DASH = 'dotDash'; //A line with alternating dots and dashes
const DOT_DOT_DASH = 'dotDotDash'; //A line with a repeating dot - dot - dash sequence
const DOTTED = 'dotted'; //A dotted line
const DOUBLE = 'double'; //A double line
const DOUBLE_WAVE = 'doubleWave'; //A double wavy line
const INSET = 'inset'; //An inset set of lines
const NIL = 'nil'; //No border
const NONE = 'none'; //No border
const OUTSET = 'outset'; //An outset set of lines
const THICK = 'thick'; //A single line
const THICK_THIN_LARGE_GAP = 'thickThinLargeGap'; //A thick line contained within a thin line with a large-sized intermediate gap
const THICK_THIN_MEDIUM_GAP = 'thickThinMediumGap'; //A thick line contained within a thin line with a medium-sized intermediate gap
const THICK_THIN_SMALL_GAP = 'thickThinSmallGap'; //A thick line contained within a thin line with a small intermediate gap
const THIN_THICK_LARGE_GAP = 'thinThickLargeGap'; //A thin line contained within a thick line with a large-sized intermediate gap
const THIN_THICK_MEDIUM_GAP = 'thinThickMediumGap'; //A thick line contained within a thin line with a medium-sized intermediate gap
const THIN_THICK_SMALL_GAP = 'thinThickSmallGap'; //A thick line contained within a thin line with a small intermediate gap
const THIN_THICK_THINLARGE_GAP = 'thinThickThinLargeGap'; //A thin-thick-thin line with a large gap
const THIN_THICK_THIN_MEDIUM_GAP = 'thinThickThinMediumGap'; //A thin-thick-thin line with a medium gap
const THIN_THICK_THIN_SMALL_GAP = 'thinThickThinSmallGap'; //A thin-thick-thin line with a small gap
const THREE_D_EMBOSS = 'threeDEmboss'; //A three-staged gradient line, getting darker towards the paragraph
const THREE_D_ENGRAVE = 'threeDEngrave'; //A three-staged gradient like, getting darker away from the paragraph
const TRIPLE = 'triple'; //A triple line
const WAVE = 'wave'; //A wavy line
}

View File

@@ -0,0 +1,55 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\SimpleType;
use PhpOffice\PhpWord\Shared\AbstractEnum;
/**
* Document Protection Types
*
* @since 0.14.0
*
* @see http://www.datypic.com/sc/ooxml/t-w_ST_DocProtect.html
*/
final class DocProtect extends AbstractEnum
{
/**
* No Editing Restrictions
*/
const NONE = 'none';
/**
* Allow No Editing
*/
const READ_ONLY = 'readOnly';
/**
* Allow Editing of Comments
*/
const COMMENTS = 'comments';
/**
* Allow Editing With Revision Tracking
*/
const TRACKED_CHANGES = 'trackedChanges';
/**
* Allow Editing of Form Fields
*/
const FORMS = 'forms';
}

View File

@@ -0,0 +1,67 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\SimpleType;
use PhpOffice\PhpWord\Shared\AbstractEnum;
/**
* Horizontal Alignment Type.
*
* Introduced in 1st Edition of ECMA-376. Initially it was intended to align paragraphs and tables.
* Since ISO/IEC-29500:2008 the type must not be used for table alignment.
*
* @since 0.13.0
*
* @see \PhpOffice\PhpWord\SimpleType\JcTable For table alignment modes available since ISO/IEC-29500:2008.
* @see http://www.datypic.com/sc/ooxml/t-w_ST_Jc.html
*/
final class Jc extends AbstractEnum
{
const START = 'start';
const CENTER = 'center';
const END = 'end';
const BOTH = 'both';
const MEDIUM_KASHIDA = 'mediumKashida';
const DISTRIBUTE = 'distribute';
const NUM_TAB = 'numTab';
const HIGH_KASHIDA = 'highKashida';
const LOW_KASHIDA = 'lowKashida';
const THAI_DISTRIBUTE = 'thaiDistribute';
/**
* Kept for compatibility with 1st edition of ECMA-376 standard.
* Microsoft Word 2007 and WPS Writer 2016 still rely on it.
*
* @deprecated 0.13.0 For documents based on ISO/IEC 29500:2008 and later use `START` instead.
*/
const LEFT = 'left';
/**
* Kept for compatibility with 1st edition of ECMA-376 standard.
* Microsoft Word 2007 and WPS Writer 2016 still rely on it.
*
* @deprecated 0.13.0 For documents based on ISO/IEC 29500:2008 and later use `END` instead.
*/
const RIGHT = 'right';
/**
* Kept for compatibility with 1st edition of ECMA-376 standard.
* Microsoft Word 2007 and WPS Writer 2016 still rely on it.
*
* @deprecated 0.13.0 For documents based on ISO/IEC 29500:2008 and later use `BOTH` instead.
*/
const JUSTIFY = 'justify';
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\SimpleType;
use PhpOffice\PhpWord\Shared\AbstractEnum;
/**
* Table Alignment Type.
*
* Introduced in ISO/IEC-29500:2008.
*
* @since 0.13.0
*/
final class JcTable extends AbstractEnum
{
const START = 'start';
const CENTER = 'center';
const END = 'end';
}

Some files were not shown because too many files have changed in this diff Show More