Merge branch '#160-element-container' into xml-reader
This commit is contained in:
commit
6456255300
14
CHANGELOG.md
14
CHANGELOG.md
|
|
@ -4,6 +4,8 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
|
||||||
|
|
||||||
## 0.9.2 - Not yet released
|
## 0.9.2 - Not yet released
|
||||||
|
|
||||||
|
This release marked heavy refactorings on internal code structure with the creation of some abstract classes to reduce code duplication. `Element` subnamespace is introduced in this release to replace `Section`.
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
- Image: Get image dimensions without EXIF extension - @andrew-kzoo GH-184
|
- Image: Get image dimensions without EXIF extension - @andrew-kzoo GH-184
|
||||||
|
|
@ -48,14 +50,16 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
|
||||||
### Miscellaneous
|
### Miscellaneous
|
||||||
|
|
||||||
- Documentation: Simplify page level docblock - @ivanlanin GH-179
|
- Documentation: Simplify page level docblock - @ivanlanin GH-179
|
||||||
- Writer: Refactor writer classes and make a new AbstractWriter abstract class - @ivanlanin GH-160
|
- Writer: Refactor writer classes and create a new `Write\AbstractWriter` abstract class - @ivanlanin GH-160
|
||||||
- General: Refactor folders: Element and Exception - @ivanlanin GH-187
|
- General: Refactor folders: `Element` and `Exception` - @ivanlanin GH-187
|
||||||
- General: Remove legacy HashTable and ZipStreamWrapper and all related properties/methods - @ivanlanin GH-187
|
- General: Remove legacy `HashTable` and `Shared\ZipStreamWrapper` and all related properties/methods - @ivanlanin GH-187
|
||||||
- Element: Create new AbstractElement abstract class - @ivanlanin GH-187
|
- Element: New `AbstractElement` abstract class - @ivanlanin GH-187
|
||||||
- Media: Refactor media class to use one method for all docPart (section, header, footer, footnote) - @ivanlanin GH-187
|
- Media: Refactor media class to use one method for all docPart (section, header, footer, footnote) - @ivanlanin GH-187
|
||||||
- General: Remove underscore prefix from all private properties name - @ivanlanin GH-187
|
- General: Remove underscore prefix from all private properties name - @ivanlanin GH-187
|
||||||
- General: Move Section Settings to Style\Section - @ivanlanin GH-187
|
- General: Move Section `Settings` to `Style\Section` - @ivanlanin GH-187
|
||||||
- General: Give `Abstract` prefix and `Interface` suffix for all abstract classes and interfaces as per [PHP-FIG recommendation](https://github.com/php-fig/fig-standards/blob/master/bylaws/002-psr-naming-conventions.md) - @ivanlanin GH-187
|
- General: Give `Abstract` prefix and `Interface` suffix for all abstract classes and interfaces as per [PHP-FIG recommendation](https://github.com/php-fig/fig-standards/blob/master/bylaws/002-psr-naming-conventions.md) - @ivanlanin GH-187
|
||||||
|
- Style: New `Style\AbstractStyle` abstract class - @ivanlanin GH-187
|
||||||
|
- Writer: New 'ODText\Base` class - @ivanlanin GH-187
|
||||||
|
|
||||||
## 0.9.1 - 27 Mar 2014
|
## 0.9.1 - 27 Mar 2014
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpWord\Element;
|
namespace PhpOffice\PhpWord\Element;
|
||||||
|
|
||||||
use PhpOffice\PhpWord\Exception\InvalidImageException;
|
|
||||||
use PhpOffice\PhpWord\Exception\InvalidObjectException;
|
use PhpOffice\PhpWord\Exception\InvalidObjectException;
|
||||||
use PhpOffice\PhpWord\Media;
|
use PhpOffice\PhpWord\Media;
|
||||||
use PhpOffice\PhpWord\Style;
|
use PhpOffice\PhpWord\Style;
|
||||||
|
|
@ -482,7 +481,6 @@ abstract class AbstractElement
|
||||||
'table' => array('section', 'header', 'footer'),
|
'table' => array('section', 'header', 'footer'),
|
||||||
'footnote' => array('section', 'textrun', 'cell'),
|
'footnote' => array('section', 'textrun', 'cell'),
|
||||||
'preservetext' => array('header', 'footer', 'cell'),
|
'preservetext' => array('header', 'footer', 'cell'),
|
||||||
'relationid' => array('header', 'footer', 'footnote'),
|
|
||||||
'title' => array('section'),
|
'title' => array('section'),
|
||||||
);
|
);
|
||||||
// Special condition, e.g. preservetext can only exists in cell when
|
// Special condition, e.g. preservetext can only exists in cell when
|
||||||
|
|
|
||||||
|
|
@ -32,13 +32,6 @@ class Image extends AbstractElement
|
||||||
*/
|
*/
|
||||||
private $style;
|
private $style;
|
||||||
|
|
||||||
/**
|
|
||||||
* Image relation ID specific only for DOCX
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $rId;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is watermark
|
* Is watermark
|
||||||
*
|
*
|
||||||
|
|
@ -155,26 +148,6 @@ class Image extends AbstractElement
|
||||||
return $this->style;
|
return $this->style;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get image relation ID
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getRelationId()
|
|
||||||
{
|
|
||||||
return $this->rId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set image relation ID
|
|
||||||
*
|
|
||||||
* @param int $rId
|
|
||||||
*/
|
|
||||||
public function setRelationId($rId)
|
|
||||||
{
|
|
||||||
$this->rId = $rId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get image source
|
* Get image source
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -31,13 +31,6 @@ class Link extends AbstractElement
|
||||||
*/
|
*/
|
||||||
private $name;
|
private $name;
|
||||||
|
|
||||||
/**
|
|
||||||
* Link Relation ID
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $relationId;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Font style
|
* Font style
|
||||||
*
|
*
|
||||||
|
|
@ -71,26 +64,6 @@ class Link extends AbstractElement
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Link Relation ID
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getRelationId()
|
|
||||||
{
|
|
||||||
return $this->relationId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set Link Relation ID
|
|
||||||
*
|
|
||||||
* @param int $rId
|
|
||||||
*/
|
|
||||||
public function setRelationId($rId)
|
|
||||||
{
|
|
||||||
$this->relationId = $rId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Link source
|
* Get Link source
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -30,13 +30,6 @@ class Object extends AbstractElement
|
||||||
*/
|
*/
|
||||||
private $style;
|
private $style;
|
||||||
|
|
||||||
/**
|
|
||||||
* Object Relation ID
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
private $relationId;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Image Relation ID
|
* Image Relation ID
|
||||||
*
|
*
|
||||||
|
|
@ -84,26 +77,6 @@ class Object extends AbstractElement
|
||||||
return $this->source;
|
return $this->source;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Object Relation ID
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getRelationId()
|
|
||||||
{
|
|
||||||
return $this->relationId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set Object Relation ID
|
|
||||||
*
|
|
||||||
* @param int $rId
|
|
||||||
*/
|
|
||||||
public function setRelationId($rId)
|
|
||||||
{
|
|
||||||
$this->relationId = $rId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Image Relation ID
|
* Get Image Relation ID
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,10 @@ abstract class AbstractReader implements ReaderInterface
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
fclose($this->fileHandle);
|
if (is_resource($this->fileHandle)) {
|
||||||
|
fclose($this->fileHandle);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PHPWord
|
||||||
|
*
|
||||||
|
* @link https://github.com/PHPOffice/PHPWord
|
||||||
|
* @copyright 2014 PHPWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Style;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract style class
|
||||||
|
*
|
||||||
|
* @since 0.9.2
|
||||||
|
*/
|
||||||
|
abstract class AbstractStyle
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Set style value template method
|
||||||
|
*
|
||||||
|
* Some child classes have their own specific overrides
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @param string $value
|
||||||
|
*
|
||||||
|
* @todo Implement type check mechanism, e.g. boolean, integer, enum, defaults
|
||||||
|
*/
|
||||||
|
public function setStyleValue($key, $value)
|
||||||
|
{
|
||||||
|
// Backward compability check for versions < 0.9.2 which use underscore
|
||||||
|
// prefix for their private properties
|
||||||
|
if (substr($key, 0, 1) == '_') {
|
||||||
|
$key = substr($key, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the set method is exists. Throws an exception?
|
||||||
|
$method = 'set' . $key;
|
||||||
|
if (method_exists($this, $method)) {
|
||||||
|
$this->$method($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -12,7 +12,7 @@ namespace PhpOffice\PhpWord\Style;
|
||||||
/**
|
/**
|
||||||
* Table cell style
|
* Table cell style
|
||||||
*/
|
*/
|
||||||
class Cell
|
class Cell extends AbstractStyle
|
||||||
{
|
{
|
||||||
const TEXT_DIR_BTLR = 'btLr';
|
const TEXT_DIR_BTLR = 'btLr';
|
||||||
const TEXT_DIR_TBRL = 'tbRl';
|
const TEXT_DIR_TBRL = 'tbRl';
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ use PhpOffice\PhpWord\Exception\InvalidStyleException;
|
||||||
/**
|
/**
|
||||||
* Font style
|
* Font style
|
||||||
*/
|
*/
|
||||||
class Font
|
class Font extends AbstractStyle
|
||||||
{
|
{
|
||||||
const UNDERLINE_NONE = 'none';
|
const UNDERLINE_NONE = 'none';
|
||||||
const UNDERLINE_DASH = 'dash';
|
const UNDERLINE_DASH = 'dash';
|
||||||
|
|
@ -202,23 +202,6 @@ class Font
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set style value
|
|
||||||
*
|
|
||||||
* @param string $key
|
|
||||||
* @param mixed $value
|
|
||||||
*/
|
|
||||||
public function setStyleValue($key, $value)
|
|
||||||
{
|
|
||||||
if (substr($key, 0, 1) == '_') {
|
|
||||||
$key = substr($key, 1);
|
|
||||||
}
|
|
||||||
$method = 'set' . $key;
|
|
||||||
if (method_exists($this, $method)) {
|
|
||||||
$this->$method($value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get font name
|
* Get font name
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ namespace PhpOffice\PhpWord\Style;
|
||||||
/**
|
/**
|
||||||
* Image and memory image style
|
* Image and memory image style
|
||||||
*/
|
*/
|
||||||
class Image
|
class Image extends AbstractStyle
|
||||||
{
|
{
|
||||||
const WRAPPING_STYLE_INLINE = 'inline';
|
const WRAPPING_STYLE_INLINE = 'inline';
|
||||||
const WRAPPING_STYLE_SQUARE = 'square';
|
const WRAPPING_STYLE_SQUARE = 'square';
|
||||||
|
|
@ -41,13 +41,6 @@ class Image
|
||||||
*/
|
*/
|
||||||
private $align;
|
private $align;
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrapping style
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $wrappingStyle;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Margin Top
|
* Margin Top
|
||||||
*
|
*
|
||||||
|
|
@ -62,6 +55,13 @@ class Image
|
||||||
*/
|
*/
|
||||||
private $marginLeft;
|
private $marginLeft;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapping style
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $wrappingStyle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new image style
|
* Create new image style
|
||||||
*/
|
*/
|
||||||
|
|
@ -75,20 +75,6 @@ class Image
|
||||||
$this->setWrappingStyle(self::WRAPPING_STYLE_INLINE);
|
$this->setWrappingStyle(self::WRAPPING_STYLE_INLINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set style value
|
|
||||||
*
|
|
||||||
* @param string $key
|
|
||||||
* @param mixed $value
|
|
||||||
*/
|
|
||||||
public function setStyleValue($key, $value)
|
|
||||||
{
|
|
||||||
if (substr($key, 0, 1) == '_') {
|
|
||||||
$key = substr($key, 1);
|
|
||||||
}
|
|
||||||
$this->$key = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get width
|
* Get width
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ namespace PhpOffice\PhpWord\Style;
|
||||||
/**
|
/**
|
||||||
* List item style
|
* List item style
|
||||||
*/
|
*/
|
||||||
class ListItem
|
class ListItem extends AbstractStyle
|
||||||
{
|
{
|
||||||
const TYPE_NUMBER = 7;
|
const TYPE_NUMBER = 7;
|
||||||
const TYPE_NUMBER_NESTED = 8;
|
const TYPE_NUMBER_NESTED = 8;
|
||||||
|
|
@ -34,20 +34,6 @@ class ListItem
|
||||||
$this->listType = self::TYPE_BULLET_FILLED;
|
$this->listType = self::TYPE_BULLET_FILLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set style value
|
|
||||||
*
|
|
||||||
* @param string $key
|
|
||||||
* @param string $value
|
|
||||||
*/
|
|
||||||
public function setStyleValue($key, $value)
|
|
||||||
{
|
|
||||||
if (substr($key, 0, 1) == '_') {
|
|
||||||
$key = substr($key, 1);
|
|
||||||
}
|
|
||||||
$this->$key = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set List Type
|
* Set List Type
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ use PhpOffice\PhpWord\Exception\InvalidStyleException;
|
||||||
/**
|
/**
|
||||||
* Paragraph style
|
* Paragraph style
|
||||||
*/
|
*/
|
||||||
class Paragraph
|
class Paragraph extends AbstractStyle
|
||||||
{
|
{
|
||||||
const LINE_HEIGHT = 240;
|
const LINE_HEIGHT = 240;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ namespace PhpOffice\PhpWord\Style;
|
||||||
/**
|
/**
|
||||||
* Table row style
|
* Table row style
|
||||||
*/
|
*/
|
||||||
class Row
|
class Row extends AbstractStyle
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Repeat table row on every new page
|
* Repeat table row on every new page
|
||||||
|
|
@ -42,20 +42,6 @@ class Row
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set style value
|
|
||||||
*
|
|
||||||
* @param string $key
|
|
||||||
* @param mixed $value
|
|
||||||
*/
|
|
||||||
public function setStyleValue($key, $value)
|
|
||||||
{
|
|
||||||
if (substr($key, 0, 1) == '_') {
|
|
||||||
$key = substr($key, 1);
|
|
||||||
}
|
|
||||||
$this->$key = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set tblHeader
|
* Set tblHeader
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ namespace PhpOffice\PhpWord\Style;
|
||||||
/**
|
/**
|
||||||
* Section settings
|
* Section settings
|
||||||
*/
|
*/
|
||||||
class Section
|
class Section extends AbstractStyle
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Default Page Size Width
|
* Default Page Size Width
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ namespace PhpOffice\PhpWord\Style;
|
||||||
/**
|
/**
|
||||||
* TOC style
|
* TOC style
|
||||||
*/
|
*/
|
||||||
class TOC
|
class TOC extends AbstractStyle
|
||||||
{
|
{
|
||||||
const TABLEADER_DOT = 'dot';
|
const TABLEADER_DOT = 'dot';
|
||||||
const TABLEADER_UNDERSCORE = 'underscore';
|
const TABLEADER_UNDERSCORE = 'underscore';
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ use PhpOffice\PhpWord\Shared\XMLWriter;
|
||||||
/**
|
/**
|
||||||
* Tab style
|
* Tab style
|
||||||
*/
|
*/
|
||||||
class Tab
|
class Tab extends AbstractStyle
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Tab Stop Type
|
* Tab Stop Type
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ namespace PhpOffice\PhpWord\Style;
|
||||||
/**
|
/**
|
||||||
* Table style
|
* Table style
|
||||||
*/
|
*/
|
||||||
class Table
|
class Table extends AbstractStyle
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Style for first row
|
* Style for first row
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ use PhpOffice\PhpWord\Shared\XMLWriter;
|
||||||
/**
|
/**
|
||||||
* Tabs style
|
* Tabs style
|
||||||
*/
|
*/
|
||||||
class Tabs
|
class Tabs extends AbstractStyle
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Tabs
|
* Tabs
|
||||||
|
|
|
||||||
|
|
@ -222,7 +222,7 @@ class Template
|
||||||
* @param string $blockname
|
* @param string $blockname
|
||||||
* @param integer $clones
|
* @param integer $clones
|
||||||
* @param boolean $replace
|
* @param boolean $replace
|
||||||
* @return null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function cloneBlock($blockname, $clones = 1, $replace = true)
|
public function cloneBlock($blockname, $clones = 1, $replace = true)
|
||||||
{
|
{
|
||||||
|
|
@ -263,7 +263,6 @@ class Template
|
||||||
* Delete a block of text
|
* Delete a block of text
|
||||||
*
|
*
|
||||||
* @param string $blockname
|
* @param string $blockname
|
||||||
* @param string $replacement
|
|
||||||
*/
|
*/
|
||||||
public function deleteBlock($blockname)
|
public function deleteBlock($blockname)
|
||||||
{
|
{
|
||||||
|
|
@ -317,7 +316,7 @@ class Template
|
||||||
*
|
*
|
||||||
* @param string $documentPartXML
|
* @param string $documentPartXML
|
||||||
* @param string $search
|
* @param string $search
|
||||||
* @param mixed $replace
|
* @param string $replace
|
||||||
* @param integer $limit
|
* @param integer $limit
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
|
@ -335,16 +334,10 @@ class Template
|
||||||
$search = '${' . $search . '}';
|
$search = '${' . $search . '}';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_array($replace)) {
|
if (!String::isUTF8($replace)) {
|
||||||
if (!String::isUTF8($replace)) {
|
$replace = utf8_encode($replace);
|
||||||
$replace = utf8_encode($replace);
|
|
||||||
}
|
|
||||||
$replace = htmlspecialchars($replace);
|
|
||||||
} else {
|
|
||||||
foreach ($replace as $key => $value) {
|
|
||||||
$replace[$key] = htmlspecialchars($value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
$replace = htmlspecialchars($replace);
|
||||||
|
|
||||||
$regExpDelim = '/';
|
$regExpDelim = '/';
|
||||||
$escapedSearch = preg_quote($search, $regExpDelim);
|
$escapedSearch = preg_quote($search, $regExpDelim);
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ namespace PhpOffice\PhpWord\Writer;
|
||||||
|
|
||||||
use PhpOffice\PhpWord\Exception\Exception;
|
use PhpOffice\PhpWord\Exception\Exception;
|
||||||
use PhpOffice\PhpWord\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
|
use PhpOffice\PhpWord\Settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract writer class
|
* Abstract writer class
|
||||||
|
|
@ -148,21 +149,21 @@ abstract class AbstractWriter implements WriterInterface
|
||||||
/**
|
/**
|
||||||
* Get temporary file name
|
* Get temporary file name
|
||||||
*
|
*
|
||||||
* If $pFilename is php://output or php://stdout, make it a temporary file
|
* If $filename is php://output or php://stdout, make it a temporary file
|
||||||
*
|
*
|
||||||
* @param string $pFilename
|
* @param string $filename
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getTempFile($pFilename)
|
protected function getTempFile($filename)
|
||||||
{
|
{
|
||||||
$this->originalFilename = $pFilename;
|
$this->originalFilename = $filename;
|
||||||
if (strtolower($pFilename) == 'php://output' || strtolower($pFilename) == 'php://stdout') {
|
if (strtolower($filename) == 'php://output' || strtolower($filename) == 'php://stdout') {
|
||||||
$pFilename = @tempnam(sys_get_temp_dir(), 'phpword_');
|
$filename = @tempnam(sys_get_temp_dir(), 'phpword_');
|
||||||
if ($pFilename == '') {
|
if ($filename == '') {
|
||||||
$pFilename = $this->originalFilename;
|
$filename = $this->originalFilename;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->tempFilename = $pFilename;
|
$this->tempFilename = $filename;
|
||||||
|
|
||||||
return $this->tempFilename;
|
return $this->tempFilename;
|
||||||
}
|
}
|
||||||
|
|
@ -181,4 +182,37 @@ abstract class AbstractWriter implements WriterInterface
|
||||||
@unlink($this->tempFilename);
|
@unlink($this->tempFilename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get ZipArchive object
|
||||||
|
*
|
||||||
|
* @param string $filename
|
||||||
|
* @return mixed ZipArchive object
|
||||||
|
*/
|
||||||
|
protected function getZipArchive($filename)
|
||||||
|
{
|
||||||
|
// Create new ZIP file and open it for writing
|
||||||
|
$zipClass = Settings::getZipClass();
|
||||||
|
$objZip = new $zipClass();
|
||||||
|
|
||||||
|
// Retrieve OVERWRITE and CREATE constants from the instantiated zip class
|
||||||
|
// This method of accessing constant values from a dynamic class should work with all appropriate versions of PHP
|
||||||
|
$ro = new \ReflectionObject($objZip);
|
||||||
|
$zipOverWrite = $ro->getConstant('OVERWRITE');
|
||||||
|
$zipCreate = $ro->getConstant('CREATE');
|
||||||
|
|
||||||
|
// Remove any existing file
|
||||||
|
if (file_exists($filename)) {
|
||||||
|
unlink($filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try opening the ZIP file
|
||||||
|
if ($objZip->open($filename, $zipOverWrite) !== true) {
|
||||||
|
if ($objZip->open($filename, $zipCreate) !== true) {
|
||||||
|
throw new Exception("Could not open " . $filename . " for writing.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $objZip;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ namespace PhpOffice\PhpWord\Writer;
|
||||||
|
|
||||||
use PhpOffice\PhpWord\Exception\Exception;
|
use PhpOffice\PhpWord\Exception\Exception;
|
||||||
use PhpOffice\PhpWord\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
use PhpOffice\PhpWord\Settings;
|
|
||||||
use PhpOffice\PhpWord\Writer\ODText\Content;
|
use PhpOffice\PhpWord\Writer\ODText\Content;
|
||||||
use PhpOffice\PhpWord\Writer\ODText\Manifest;
|
use PhpOffice\PhpWord\Writer\ODText\Manifest;
|
||||||
use PhpOffice\PhpWord\Writer\ODText\Meta;
|
use PhpOffice\PhpWord\Writer\ODText\Meta;
|
||||||
|
|
@ -47,35 +46,14 @@ class ODText extends AbstractWriter implements WriterInterface
|
||||||
/**
|
/**
|
||||||
* Save PhpWord to file
|
* Save PhpWord to file
|
||||||
*
|
*
|
||||||
* @param string $pFilename
|
* @param string $filename
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function save($pFilename = null)
|
public function save($filename = null)
|
||||||
{
|
{
|
||||||
if (!is_null($this->phpWord)) {
|
if (!is_null($this->phpWord)) {
|
||||||
$pFilename = $this->getTempFile($pFilename);
|
$filename = $this->getTempFile($filename);
|
||||||
|
$objZip = $this->getZipArchive($filename);
|
||||||
// Create new ZIP file and open it for writing
|
|
||||||
$zipClass = Settings::getZipClass();
|
|
||||||
$objZip = new $zipClass();
|
|
||||||
|
|
||||||
// Retrieve OVERWRITE and CREATE constants from the instantiated zip class
|
|
||||||
// This method of accessing constant values from a dynamic class should work with all appropriate versions of PHP
|
|
||||||
$ro = new \ReflectionObject($objZip);
|
|
||||||
$zipOverWrite = $ro->getConstant('OVERWRITE');
|
|
||||||
$zipCreate = $ro->getConstant('CREATE');
|
|
||||||
|
|
||||||
// Remove any existing file
|
|
||||||
if (file_exists($pFilename)) {
|
|
||||||
unlink($pFilename);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try opening the ZIP file
|
|
||||||
if ($objZip->open($pFilename, $zipOverWrite) !== true) {
|
|
||||||
if ($objZip->open($pFilename, $zipCreate) !== true) {
|
|
||||||
throw new Exception("Could not open " . $pFilename . " for writing.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add mimetype to ZIP file
|
// Add mimetype to ZIP file
|
||||||
//@todo Not in \ZipArchive::CM_STORE mode
|
//@todo Not in \ZipArchive::CM_STORE mode
|
||||||
|
|
@ -95,7 +73,7 @@ class ODText extends AbstractWriter implements WriterInterface
|
||||||
|
|
||||||
// Close file
|
// Close file
|
||||||
if ($objZip->close() === false) {
|
if ($objZip->close() === false) {
|
||||||
throw new Exception("Could not close zip file $pFilename.");
|
throw new Exception("Could not close zip file $filename.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->cleanupTempFile();
|
$this->cleanupTempFile();
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,93 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PHPWord
|
||||||
|
*
|
||||||
|
* @link https://github.com/PHPOffice/PHPWord
|
||||||
|
* @copyright 2014 PHPWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Writer\ODText;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
|
use PhpOffice\PhpWord\Style;
|
||||||
|
use PhpOffice\PhpWord\Style\Font;
|
||||||
|
use PhpOffice\PhpWord\Shared\XMLWriter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ODT base part writer
|
||||||
|
*
|
||||||
|
* @since 0.9.2
|
||||||
|
*/
|
||||||
|
class Base extends AbstractWriterPart
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Write common root attributes
|
||||||
|
*/
|
||||||
|
protected function writeCommonRootAttributes(XMLWriter $xmlWriter)
|
||||||
|
{
|
||||||
|
$xmlWriter->writeAttribute('office:version', '1.2');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write font faces declaration
|
||||||
|
*/
|
||||||
|
protected function writeFontFaces(XMLWriter $xmlWriter)
|
||||||
|
{
|
||||||
|
$xmlWriter->startElement('office:font-face-decls');
|
||||||
|
$arrFonts = array();
|
||||||
|
$styles = Style::getStyles();
|
||||||
|
$numFonts = 0;
|
||||||
|
if (count($styles) > 0) {
|
||||||
|
foreach ($styles as $styleName => $style) {
|
||||||
|
// Font
|
||||||
|
if ($style instanceof Font) {
|
||||||
|
$numFonts++;
|
||||||
|
$name = $style->getName();
|
||||||
|
if (!in_array($name, $arrFonts)) {
|
||||||
|
$arrFonts[] = $name;
|
||||||
|
|
||||||
|
// style:font-face
|
||||||
|
$xmlWriter->startElement('style:font-face');
|
||||||
|
$xmlWriter->writeAttribute('style:name', $name);
|
||||||
|
$xmlWriter->writeAttribute('svg:font-family', $name);
|
||||||
|
$xmlWriter->endElement();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!in_array(PhpWord::DEFAULT_FONT_NAME, $arrFonts)) {
|
||||||
|
$xmlWriter->startElement('style:font-face');
|
||||||
|
$xmlWriter->writeAttribute('style:name', PhpWord::DEFAULT_FONT_NAME);
|
||||||
|
$xmlWriter->writeAttribute('svg:font-family', PhpWord::DEFAULT_FONT_NAME);
|
||||||
|
$xmlWriter->endElement();
|
||||||
|
}
|
||||||
|
$xmlWriter->endElement();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -29,7 +29,7 @@ use PhpOffice\PhpWord\TOC;
|
||||||
/**
|
/**
|
||||||
* ODText content part writer
|
* ODText content part writer
|
||||||
*/
|
*/
|
||||||
class Content extends AbstractWriterPart
|
class Content extends Base
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Write content file to XML format
|
* Write content file to XML format
|
||||||
|
|
@ -51,38 +51,12 @@ class Content extends AbstractWriterPart
|
||||||
|
|
||||||
// office:document-content
|
// office:document-content
|
||||||
$xmlWriter->startElement('office:document-content');
|
$xmlWriter->startElement('office:document-content');
|
||||||
$xmlWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
|
$this->writeCommonRootAttributes($xmlWriter);
|
||||||
$xmlWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:xforms', 'http://www.w3.org/2002/xforms');
|
$xmlWriter->writeAttribute('xmlns:xforms', 'http://www.w3.org/2002/xforms');
|
||||||
$xmlWriter->writeAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema');
|
$xmlWriter->writeAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema');
|
||||||
$xmlWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
|
$xmlWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
|
||||||
$xmlWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:field', 'urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0');
|
$xmlWriter->writeAttribute('xmlns:field', 'urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0');
|
||||||
$xmlWriter->writeAttribute('xmlns:formx', 'urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0');
|
$xmlWriter->writeAttribute('xmlns:formx', 'urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0');
|
||||||
$xmlWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
|
|
||||||
$xmlWriter->writeAttribute('office:version', '1.2');
|
|
||||||
|
|
||||||
// We firstly search all fonts used
|
// We firstly search all fonts used
|
||||||
$sections = $phpWord->getSections();
|
$sections = $phpWord->getSections();
|
||||||
|
|
@ -122,37 +96,9 @@ class Content extends AbstractWriterPart
|
||||||
}
|
}
|
||||||
|
|
||||||
// office:font-face-decls
|
// office:font-face-decls
|
||||||
$xmlWriter->startElement('office:font-face-decls');
|
$this->writeFontFaces($xmlWriter);
|
||||||
$arrFonts = array();
|
|
||||||
|
|
||||||
$styles = Style::getStyles();
|
|
||||||
$numFonts = 0;
|
|
||||||
if (count($styles) > 0) {
|
|
||||||
foreach ($styles as $styleName => $style) {
|
|
||||||
// Font
|
|
||||||
if ($style instanceof Font) {
|
|
||||||
$numFonts++;
|
|
||||||
$name = $style->getName();
|
|
||||||
if (!in_array($name, $arrFonts)) {
|
|
||||||
$arrFonts[] = $name;
|
|
||||||
|
|
||||||
// style:font-face
|
|
||||||
$xmlWriter->startElement('style:font-face');
|
|
||||||
$xmlWriter->writeAttribute('style:name', $name);
|
|
||||||
$xmlWriter->writeAttribute('svg:font-family', $name);
|
|
||||||
$xmlWriter->endElement();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!in_array(PhpWord::DEFAULT_FONT_NAME, $arrFonts)) {
|
|
||||||
$xmlWriter->startElement('style:font-face');
|
|
||||||
$xmlWriter->writeAttribute('style:name', PhpWord::DEFAULT_FONT_NAME);
|
|
||||||
$xmlWriter->writeAttribute('svg:font-family', PhpWord::DEFAULT_FONT_NAME);
|
|
||||||
$xmlWriter->endElement();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$xmlWriter->endElement();
|
|
||||||
|
|
||||||
|
// office:automatic-styles
|
||||||
$xmlWriter->startElement('office:automatic-styles');
|
$xmlWriter->startElement('office:automatic-styles');
|
||||||
$styles = Style::getStyles();
|
$styles = Style::getStyles();
|
||||||
$numPStyles = 0;
|
$numPStyles = 0;
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpWord\Writer\ODText;
|
namespace PhpOffice\PhpWord\Writer\ODText;
|
||||||
|
|
||||||
use PhpOffice\PhpWord\Exception\Exception;
|
|
||||||
use PhpOffice\PhpWord\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -33,8 +32,8 @@ class Manifest extends AbstractWriterPart
|
||||||
|
|
||||||
// manifest:manifest
|
// manifest:manifest
|
||||||
$xmlWriter->startElement('manifest:manifest');
|
$xmlWriter->startElement('manifest:manifest');
|
||||||
$xmlWriter->writeAttribute('xmlns:manifest', 'urn:oasis:names:tc:opendocument:xmlns:manifest:1.0');
|
|
||||||
$xmlWriter->writeAttribute('manifest:version', '1.2');
|
$xmlWriter->writeAttribute('manifest:version', '1.2');
|
||||||
|
$xmlWriter->writeAttribute('xmlns:manifest', 'urn:oasis:names:tc:opendocument:xmlns:manifest:1.0');
|
||||||
|
|
||||||
// manifest:file-entry
|
// manifest:file-entry
|
||||||
$xmlWriter->startElement('manifest:file-entry');
|
$xmlWriter->startElement('manifest:file-entry');
|
||||||
|
|
|
||||||
|
|
@ -36,13 +36,13 @@ class Meta extends AbstractWriterPart
|
||||||
|
|
||||||
// office:document-meta
|
// office:document-meta
|
||||||
$xmlWriter->startElement('office:document-meta');
|
$xmlWriter->startElement('office:document-meta');
|
||||||
|
$xmlWriter->writeAttribute('office:version', '1.2');
|
||||||
$xmlWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
|
$xmlWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
|
||||||
$xmlWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
|
$xmlWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
|
||||||
$xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
|
$xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
|
||||||
$xmlWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
|
$xmlWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
|
||||||
$xmlWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
|
$xmlWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
|
||||||
$xmlWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
|
$xmlWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
|
||||||
$xmlWriter->writeAttribute('office:version', '1.2');
|
|
||||||
|
|
||||||
// office:meta
|
// office:meta
|
||||||
$xmlWriter->startElement('office:meta');
|
$xmlWriter->startElement('office:meta');
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ use PhpOffice\PhpWord\Style\Table;
|
||||||
/**
|
/**
|
||||||
* ODText styloes part writer
|
* ODText styloes part writer
|
||||||
*/
|
*/
|
||||||
class Styles extends AbstractWriterPart
|
class Styles extends Base
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Write Styles file to XML format
|
* Write Styles file to XML format
|
||||||
|
|
@ -40,65 +40,10 @@ class Styles extends AbstractWriterPart
|
||||||
|
|
||||||
// Styles:Styles
|
// Styles:Styles
|
||||||
$xmlWriter->startElement('office:document-styles');
|
$xmlWriter->startElement('office:document-styles');
|
||||||
$xmlWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
|
$this->writeCommonRootAttributes($xmlWriter);
|
||||||
$xmlWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table');
|
|
||||||
$xmlWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
|
|
||||||
$xmlWriter->writeAttribute('office:version', '1.2');
|
|
||||||
|
|
||||||
|
|
||||||
// office:font-face-decls
|
// office:font-face-decls
|
||||||
$xmlWriter->startElement('office:font-face-decls');
|
$this->writeFontFaces($xmlWriter);
|
||||||
$arrFonts = array();
|
|
||||||
$styles = Style::getStyles();
|
|
||||||
$numFonts = 0;
|
|
||||||
if (count($styles) > 0) {
|
|
||||||
foreach ($styles as $styleName => $style) {
|
|
||||||
// Font
|
|
||||||
if ($style instanceof Font) {
|
|
||||||
$numFonts++;
|
|
||||||
$name = $style->getName();
|
|
||||||
if (!in_array($name, $arrFonts)) {
|
|
||||||
$arrFonts[] = $name;
|
|
||||||
|
|
||||||
// style:font-face
|
|
||||||
$xmlWriter->startElement('style:font-face');
|
|
||||||
$xmlWriter->writeAttribute('style:name', $name);
|
|
||||||
$xmlWriter->writeAttribute('svg:font-family', $name);
|
|
||||||
$xmlWriter->endElement();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!in_array(PhpWord::DEFAULT_FONT_NAME, $arrFonts)) {
|
|
||||||
$xmlWriter->startElement('style:font-face');
|
|
||||||
$xmlWriter->writeAttribute('style:name', PhpWord::DEFAULT_FONT_NAME);
|
|
||||||
$xmlWriter->writeAttribute('svg:font-family', PhpWord::DEFAULT_FONT_NAME);
|
|
||||||
$xmlWriter->endElement();
|
|
||||||
}
|
|
||||||
$xmlWriter->endElement();
|
|
||||||
|
|
||||||
// office:styles
|
// office:styles
|
||||||
$xmlWriter->startElement('office:styles');
|
$xmlWriter->startElement('office:styles');
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ use PhpOffice\PhpWord\Exception\Exception;
|
||||||
use PhpOffice\PhpWord\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
use PhpOffice\PhpWord\Footnote;
|
use PhpOffice\PhpWord\Footnote;
|
||||||
use PhpOffice\PhpWord\Media;
|
use PhpOffice\PhpWord\Media;
|
||||||
use PhpOffice\PhpWord\Settings;
|
|
||||||
use PhpOffice\PhpWord\Writer\Word2007\ContentTypes;
|
use PhpOffice\PhpWord\Writer\Word2007\ContentTypes;
|
||||||
use PhpOffice\PhpWord\Writer\Word2007\Rels;
|
use PhpOffice\PhpWord\Writer\Word2007\Rels;
|
||||||
use PhpOffice\PhpWord\Writer\Word2007\DocProps;
|
use PhpOffice\PhpWord\Writer\Word2007\DocProps;
|
||||||
|
|
@ -69,34 +68,13 @@ class Word2007 extends AbstractWriter implements WriterInterface
|
||||||
/**
|
/**
|
||||||
* Save document by name
|
* Save document by name
|
||||||
*
|
*
|
||||||
* @param string $pFilename
|
* @param string $filename
|
||||||
*/
|
*/
|
||||||
public function save($pFilename = null)
|
public function save($filename = null)
|
||||||
{
|
{
|
||||||
if (!is_null($this->phpWord)) {
|
if (!is_null($this->phpWord)) {
|
||||||
$pFilename = $this->getTempFile($pFilename);
|
$filename = $this->getTempFile($filename);
|
||||||
|
$objZip = $this->getZipArchive($filename);
|
||||||
// Create new ZIP file and open it for writing
|
|
||||||
$zipClass = Settings::getZipClass();
|
|
||||||
$objZip = new $zipClass();
|
|
||||||
|
|
||||||
// Retrieve OVERWRITE and CREATE constants from the instantiated zip class
|
|
||||||
// This method of accessing constant values from a dynamic class should work with all appropriate versions of PHP
|
|
||||||
$ro = new \ReflectionObject($objZip);
|
|
||||||
$zipOverWrite = $ro->getConstant('OVERWRITE');
|
|
||||||
$zipCreate = $ro->getConstant('CREATE');
|
|
||||||
|
|
||||||
// Remove any existing file
|
|
||||||
if (file_exists($pFilename)) {
|
|
||||||
unlink($pFilename);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try opening the ZIP file
|
|
||||||
if ($objZip->open($pFilename, $zipOverWrite) !== true) {
|
|
||||||
if ($objZip->open($pFilename, $zipCreate) !== true) {
|
|
||||||
throw new Exception("Could not open " . $pFilename . " for writing.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Content types
|
// Content types
|
||||||
$this->cTypes['default'] = array(
|
$this->cTypes['default'] = array(
|
||||||
|
|
@ -156,7 +134,7 @@ class Word2007 extends AbstractWriter implements WriterInterface
|
||||||
|
|
||||||
// Close file
|
// Close file
|
||||||
if ($objZip->close() === false) {
|
if ($objZip->close() === false) {
|
||||||
throw new Exception("Could not close zip file $pFilename.");
|
throw new Exception("Could not close zip file $filename.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->cleanupTempFile();
|
$this->cleanupTempFile();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue