Merge pull request #185 from ivanlanin/#140-bskrtich-pclzip

Add PCLZIP alternative to ZipArchive (merge and close #140)
This commit is contained in:
Ivan Lanin 2014-03-31 00:33:41 +07:00
commit e405bf2b71
42 changed files with 7083 additions and 1210 deletions

View File

@ -37,7 +37,7 @@ before_script:
script:
## PHP_CodeSniffer
- phpcs --standard=PSR2 -n src/
- phpcs --standard=PSR2 -n src/ --ignore=src/PhpWord/Shared/PCLZip
- phpcs --standard=PSR2 -n tests/
## PHP Copy/Paste Detector
#- php phpcpd.phar --verbose src/

View File

@ -13,6 +13,7 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
- Font: Add `bgColor` to font style to define background using HEX color - @jcarignan GH-168
- Table: Add `exactHeight` to row style to define whether row height should be exact or atLeast - @jcarignan GH-168
- Element: New `CheckBox` element for sections and table cells - @ozilion GH-156
- Settings: Ability to use PCLZip as alternative to ZipArchive - @bskrtich @ivanlanin GH-106 GH-140 GH-185
### Bugfixes

View File

@ -7,7 +7,8 @@ Basic example
-------------
The following is a basic example of the PHPWord library. More examples
are provided in the `samples folder <https://github.com/PHPOffice/PHPWord/tree/master/samples/>`__.
are provided in the `samples
folder <https://github.com/PHPOffice/PHPWord/tree/master/samples/>`__.
.. code-block:: php
@ -52,6 +53,42 @@ are provided in the `samples folder <https://github.com/PHPOffice/PHPWord/tree/m
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'RTF');
$objWriter->save('helloWorld.rtf');
Settings
--------
The ``PhpOffice\PhpWord\Settings`` class provides some options that will
affect the behavior of PHPWord. Below are the options.
XML Writer compatibility
~~~~~~~~~~~~~~~~~~~~~~~~
This option sets
```XMLWriter::setIndent`` <http://www.php.net/manual/en/function.xmlwriter-set-indent.php>`__
and
```XMLWriter::setIndentString`` <http://www.php.net/manual/en/function.xmlwriter-set-indent-string.php>`__.
The default value of this option is ``true`` (compatible), which is
`required for OpenOffice <https://github.com/PHPOffice/PHPWord/issues/103>`__ to
render OOXML document correctly. You can set this option to ``false``
during development to make the resulting XML file easier to read.
.. code-block:: php
PhpOffice\PhpWord\Settings::setCompatibility(false);
Zip class
~~~~~~~~~
By default, PHPWord uses PHP
`ZipArchive <http://php.net/manual/en/book.zip.php>`__ to read or write
ZIP compressed archive and the files inside them. If you can't have
ZipArchive installed on your server, you can use pure PHP library
alternative, `PCLZip <http://www.phpconcept.net/pclzip/>`__, which
included with PHPWord.
.. code-block:: php
PhpOffice\PhpWord\Settings::setZipClass(PhpOffice\PhpWord\Settings::PCLZIP);
Default font
------------
@ -105,3 +142,4 @@ points to twips.
$sectionStyle->setMarginLeft(\PhpOffice\PhpWord\Shared\Font::inchSizeToTwips(.5));
// 2 cm right margin
$sectionStyle->setMarginRight(\PhpOffice\PhpWord\Shared\Font::centimeterSizeToTwips(2));

View File

@ -16,6 +16,9 @@
<filter>
<whitelist>
<directory suffix=".php">./src</directory>
<exclude>
<directory suffix=".php">./src/PhpWord/Shared/PCLZip</directory>
</exclude>
</whitelist>
</filter>
</phpunit>

View File

@ -39,14 +39,14 @@ class DocumentProperties
/**
* Created
*
* @var datetime
* @var datetime|int
*/
private $_created;
/**
* Modified
*
* @var datetime
* @var datetime|int
*/
private $_modified;
@ -102,7 +102,7 @@ class DocumentProperties
/**
* Custom Properties
*
* @var string
* @var array
*/
private $_customProperties = array();
@ -542,26 +542,21 @@ class DocumentProperties
case 'ui8': // 8-Byte Unsigned Integer
case 'uint': // Unsigned Integer
return self::PROPERTY_TYPE_INTEGER;
break;
case 'r4': // 4-Byte Real Number
case 'r8': // 8-Byte Real Number
case 'decimal': // Decimal
return self::PROPERTY_TYPE_FLOAT;
break;
case 'empty': // Empty
case 'null': // Null
case 'lpstr': // LPSTR
case 'lpwstr': // LPWSTR
case 'bstr': // Basic String
return self::PROPERTY_TYPE_STRING;
break;
case 'date': // Date and Time
case 'filetime': // File Time
return self::PROPERTY_TYPE_DATE;
break;
case 'bool': // Boolean
return self::PROPERTY_TYPE_BOOLEAN;
break;
case 'cy': // Currency
case 'error': // Error Status Code
case 'vector': // Vector
@ -576,7 +571,6 @@ class DocumentProperties
case 'clsid': // Class ID
case 'cf': // Clipboard Data
return self::PROPERTY_TYPE_UNKNOWN;
break;
}
return self::PROPERTY_TYPE_UNKNOWN;
}

View File

@ -10,6 +10,7 @@
namespace PhpOffice\PhpWord\Reader;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\DocumentProperties;
use PhpOffice\PhpWord\Exceptions\Exception;
@ -34,7 +35,8 @@ class Word2007 extends Reader implements IReader
$return = false;
// Load file
$zip = new \ZipArchive();
$zipClass = Settings::getZipClass();
$zip = new $zipClass();
if ($zip->open($pFilename) === true) {
// check if it is an OOXML archive
$rels = simplexml_load_string($this->getFromZipArchive($zip, "_rels/.rels"));
@ -59,7 +61,7 @@ class Word2007 extends Reader implements IReader
/**
* Get zip content
*
* @param \ZipArchive $archive
* @param mixed $archive
* @param string $fileName
* @param bool $removeNamespace
* @return mixed
@ -101,7 +103,8 @@ class Word2007 extends Reader implements IReader
// Initialisations
$word = new PhpWord();
$zip = new \ZipArchive();
$zipClass = Settings::getZipClass();
$zip = new $zipClass();
$zip->open($pFilename);
// Read properties and documents

View File

@ -17,7 +17,6 @@ use PhpOffice\PhpWord\Section\Link;
use PhpOffice\PhpWord\Section\ListItem;
use PhpOffice\PhpWord\Section\Object;
use PhpOffice\PhpWord\Section\PageBreak;
use PhpOffice\PhpWord\Section\Settings;
use PhpOffice\PhpWord\Section\Table;
use PhpOffice\PhpWord\Section\Text;
use PhpOffice\PhpWord\Section\TextBreak;
@ -76,7 +75,7 @@ class Section
public function __construct($sectionCount, $settings = null)
{
$this->_sectionCount = $sectionCount;
$this->_settings = new Settings();
$this->_settings = new \PhpOffice\PhpWord\Section\Settings();
$this->setSettings($settings);
}

View File

@ -34,14 +34,14 @@ class CheckBox
/**
* Text style
*
* @var Font
* @var string|Font
*/
private $fontStyle;
/**
* Paragraph style
*
* @var Paragraph
* @var string|Paragraph
*/
private $paragraphStyle;
@ -50,8 +50,8 @@ class CheckBox
*
* @param string $name
* @param string $text
* @param Font $fontStyle
* @param Paragraph $paragraphStyle
* @param mixed $fontStyle
* @param mixed $paragraphStyle
*/
public function __construct($name = null, $text = null, $fontStyle = null, $paragraphStyle = null)
{
@ -66,9 +66,9 @@ class CheckBox
/**
* Set Text style
*
* @param Font $style
* @param Paragraph $paragraphStyle
* @return Font
* @param mixed $style
* @param mixed $paragraphStyle
* @return string|Font
*/
public function setFontStyle($style = null, $paragraphStyle = null)
{
@ -90,7 +90,7 @@ class CheckBox
/**
* Get Text style
*
* @return Font
* @return string|Font
*/
public function getFontStyle()
{
@ -100,8 +100,8 @@ class CheckBox
/**
* Set Paragraph style
*
* @param Paragraph $style
* @return Paragraph
* @param mixed $style
* @return string|Paragraph
*/
public function setParagraphStyle($style = null)
{
@ -121,7 +121,7 @@ class CheckBox
/**
* Get Paragraph style
*
* @return Paragraph
* @return string|Paragraph
*/
public function getParagraphStyle()
{

View File

@ -27,14 +27,14 @@ class PreserveText
/**
* Text style
*
* @var \PhpOffice\PhpWord\Style\Font
* @var string|Font
*/
private $_styleFont;
/**
* Paragraph style
*
* @var \PhpOffice\PhpWord\Style\Paragraph
* @var string|Paragraph
*/
private $_styleParagraph;
@ -45,7 +45,7 @@ class PreserveText
* @param string $text
* @param mixed $styleFont
* @param mixed $styleParagraph
* @return PHPWord_Section_Footer_PreserveText
* @return $this
*/
public function __construct($text = null, $styleFont = null, $styleParagraph = null)
{
@ -88,7 +88,7 @@ class PreserveText
/**
* Get Text style
*
* @return \PhpOffice\PhpWord\Style\Font
* @return string|Font
*/
public function getFontStyle()
{
@ -98,7 +98,7 @@ class PreserveText
/**
* Get Paragraph style
*
* @return \PhpOffice\PhpWord\Style\Paragraph
* @return string|Paragraph
*/
public function getParagraphStyle()
{

View File

@ -41,14 +41,14 @@ class Link
/**
* Link style
*
* @var \PhpOffice\PhpWord\Style\Font
* @var string|Font
*/
private $_styleFont;
/**
* Paragraph style
*
* @var \PhpOffice\PhpWord\Style\Paragraph
* @var string|Paragraph
*/
private $_styleParagraph;
@ -140,7 +140,7 @@ class Link
/**
* Get Text style
*
* @return \PhpOffice\PhpWord\Style\Font
* @return string|Font
*/
public function getFontStyle()
{
@ -150,7 +150,7 @@ class Link
/**
* Get Paragraph style
*
* @return \PhpOffice\PhpWord\Style\Paragraph
* @return string|Paragraph
*/
public function getParagraphStyle()
{

View File

@ -27,14 +27,14 @@ class Text
/**
* Text style
*
* @var \PhpOffice\PhpWord\Style\Font
* @var string|Font
*/
private $fontStyle;
/**
* Paragraph style
*
* @var \PhpOffice\PhpWord\Style\Paragraph
* @var string|Paragraph
*/
private $paragraphStyle;
@ -42,8 +42,8 @@ class Text
* Create a new Text Element
*
* @param string $text
* @param null|array|\PhpOffice\PhpWord\Style\Font $fontStyle
* @param null|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
* @param mixed $fontStyle
* @param mixed $paragraphStyle
*/
public function __construct($text = null, $fontStyle = null, $paragraphStyle = null)
{
@ -55,9 +55,9 @@ class Text
/**
* Set Text style
*
* @param null|array|\PhpOffice\PhpWord\Style\Font $style
* @param null|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
* @return \PhpOffice\PhpWord\Style\Font
* @param string|array|Font $style
* @param string|array|Paragraph $paragraphStyle
* @return string|Font
*/
public function setFontStyle($style = null, $paragraphStyle = null)
{
@ -79,7 +79,7 @@ class Text
/**
* Get Text style
*
* @return \PhpOffice\PhpWord\Style\Font
* @return string|Font
*/
public function getFontStyle()
{
@ -89,8 +89,8 @@ class Text
/**
* Set Paragraph style
*
* @param null|array|\PhpOffice\PhpWord\Style\Paragraph $style
* @return null|\PhpOffice\PhpWord\Style\Paragraph
* @param string|array|Paragraph $style
* @return string|Paragraph
*/
public function setParagraphStyle($style = null)
{
@ -110,7 +110,7 @@ class Text
/**
* Get Paragraph style
*
* @return \PhpOffice\PhpWord\Style\Paragraph
* @return string|Paragraph
*/
public function getParagraphStyle()
{

View File

@ -20,14 +20,14 @@ class TextBreak
/**
* Paragraph style
*
* @var \PhpOffice\PhpWord\Style\Pagaraph
* @var string|Paragraph
*/
private $paragraphStyle = null;
/**
* Text style
*
* @var \PhpOffice\PhpWord\Style\Font
* @var string|Font
*/
private $fontStyle = null;
@ -50,9 +50,9 @@ class TextBreak
/**
* Set Text style
*
* @param null|array|\PhpOffice\PhpWord\Style\Font $style
* @param null|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
* @return \PhpOffice\PhpWord\Style\Font
* @param mixed $style
* @param mixed $paragraphStyle
* @return string|Font
*/
public function setFontStyle($style = null, $paragraphStyle = null)
{
@ -72,7 +72,7 @@ class TextBreak
/**
* Get Text style
*
* @return \PhpOffice\PhpWord\Style\Font
* @return string|Font
*/
public function getFontStyle()
{
@ -82,8 +82,8 @@ class TextBreak
/**
* Set Paragraph style
*
* @param null|array|\PhpOffice\PhpWord\Style\Paragraph $style
* @return null|\PhpOffice\PhpWord\Style\Paragraph
* @param string|array|Paragraph $style
* @return string|Paragraph
*/
public function setParagraphStyle($style = null)
{
@ -101,7 +101,7 @@ class TextBreak
/**
* Get Paragraph style
*
* @return \PhpOffice\PhpWord\Style\Paragraph
* @return string|Paragraph
*/
public function getParagraphStyle()
{

View File

@ -12,6 +12,7 @@ namespace PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Exceptions\InvalidImageException;
use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\Shared\String;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
/**
@ -22,7 +23,7 @@ class TextRun
/**
* Paragraph style
*
* @var \PhpOffice\PhpWord\Style\Paragraph
* @var Paragraph
*/
private $_styleParagraph;
@ -123,8 +124,8 @@ class TextRun
* Add TextBreak
*
* @param int $count
* @param null|string|array|\PhpOffice\PhpWord\Style\Font $fontStyle
* @param null|string|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
* @param mixed $fontStyle
* @param mixed $paragraphStyle
*/
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
{
@ -161,7 +162,7 @@ class TextRun
/**
* Get Paragraph style
*
* @return \PhpOffice\PhpWord\Style\Paragraph
* @return string|Paragraph
*/
public function getParagraphStyle()
{

View File

@ -14,6 +14,10 @@ namespace PhpOffice\PhpWord;
*/
class Settings
{
/** Available Zip library classes */
const PCLZIP = 'PhpOffice\\PhpWord\\Shared\\ZipArchive';
const ZIPARCHIVE = 'ZipArchive';
/**
* Compatibility option for XMLWriter
*
@ -21,6 +25,15 @@ class Settings
*/
private static $_xmlWriterCompatibility = true;
/**
* Name of the class used for Zip file management
* e.g.
* ZipArchive
*
* @var string
*/
private static $_zipClass = self::ZIPARCHIVE;
/**
* Set the compatibility option used by the XMLWriter
*
@ -45,4 +58,34 @@ class Settings
{
return self::$_xmlWriterCompatibility;
}
/**
* Set the Zip handler Class that PHPWord should use for Zip file management (PCLZip or ZipArchive)
*
* @param string $zipClass The Zip handler class that PHPWord should use for Zip file management
* e.g. Settings::PCLZip or Settings::ZipArchive
* @return boolean Success or failure
*/
public static function setZipClass($zipClass)
{
if (($zipClass === self::PCLZIP) ||
($zipClass === self::ZIPARCHIVE)) {
self::$_zipClass = $zipClass;
return true;
}
return false;
} // function setZipClass()
/**
* Return the name of the Zip handler Class that PHPWord is configured to use (PCLZip or ZipArchive)
* or Zip file management
*
* @return string Name of the Zip handler Class that PHPWord is configured to use
* for Zip file management
* e.g. Settings::PCLZip or Settings::ZipArchive
*/
public static function getZipClass()
{
return self::$_zipClass;
} // function getZipClass()
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,204 @@
<?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\Shared;
use PhpOffice\PhpWord\Exceptions\Exception;
// @codeCoverageIgnoreStart
if (!defined('PCLZIP_TEMPORARY_DIR')) {
// PCLZIP needs the temp path to end in a back slash
define('PCLZIP_TEMPORARY_DIR', sys_get_temp_dir() . '/');
}
require_once 'PCLZip/pclzip.lib.php';
// @codeCoverageIgnoreEnd
/**
* PCLZip wrapper
*
* @since 0.9.2
*/
class ZipArchive
{
/** constants */
const OVERWRITE = 'OVERWRITE';
const CREATE = 'CREATE';
/**
* Temporary storage directory
*
* @var string
*/
private $_tempDir;
/**
* Zip Archive Stream Handle
*
* @var string
*/
private $_zip;
/**
* Open a new zip archive
*
* @param string $fileName Filename for the zip archive
* @return boolean
*/
public function open($fileName)
{
$this->_tempDir = sys_get_temp_dir();
$this->_zip = new \PclZip($fileName);
return true;
}
/**
* Close this zip archive
*
* @codeCoverageIgnore
*/
public function close()
{
}
/**
* Add a new file to the zip archive.
*
* @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
*/
public function addFile($filename, $localname = null)
{
$filename = realpath($filename);
$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
if ($filenameParts['basename'] != $localnameParts['basename']) {
$temppath = $this->_tempDir . '/' . $localnameParts['basename'];
copy($filename, $temppath);
$filename = $temppath;
$filenameParts = pathinfo($temppath);
}
$res = $this->_zip->add(
$filename,
PCLZIP_OPT_REMOVE_PATH,
$filenameParts['dirname'],
PCLZIP_OPT_ADD_PATH,
$localnameParts["dirname"]
);
if ($res == 0) {
throw new Exception("Error zipping files : " . $this->_zip->errorInfo(true));
return false;
}
return true;
}
/**
* Add a new file to the zip archive from a string of raw data.
*
* @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
*/
public function addFromString($localname, $contents)
{
$filenameParts = pathinfo($localname);
// Write $contents to a temp file
$handle = fopen($this->_tempDir . '/' . $filenameParts["basename"], "wb");
fwrite($handle, $contents);
fclose($handle);
// Add temp file to zip
$res = $this->_zip->add(
$this->_tempDir . '/' . $filenameParts["basename"],
PCLZIP_OPT_REMOVE_PATH,
$this->_tempDir,
PCLZIP_OPT_ADD_PATH,
$filenameParts["dirname"]
);
if ($res == 0) {
throw new Exception("Error zipping files : " . $this->_zip->errorInfo(true));
return false;
}
// Remove temp file
unlink($this->_tempDir . '/' . $filenameParts["basename"]);
return true;
}
/**
* Find if given fileName exist in archive (Emulate ZipArchive locateName())
*
* @param string $fileName Filename for the file in zip archive
* @return boolean
*/
public function locateName($fileName)
{
$list = $this->_zip->listContent();
$listCount = count($list);
$list_index = -1;
for ($i = 0; $i < $listCount; ++$i) {
if (strtolower($list[$i]["filename"]) == strtolower($fileName) ||
strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) {
$list_index = $i;
break;
}
}
return ($list_index > -1);
}
/**
* Extract file from archive by given fileName (Emulate ZipArchive getFromName())
*
* @param string $fileName Filename for the file in zip archive
* @return string $contents File string contents
*/
public function getFromName($fileName)
{
$list = $this->_zip->listContent();
$listCount = count($list);
$list_index = -1;
for ($i = 0; $i < $listCount; ++$i) {
if (strtolower($list[$i]["filename"]) == strtolower($fileName) ||
strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) {
$list_index = $i;
break;
}
}
$extracted = "";
if ($list_index != -1) {
$extracted = $this->_zip->extractByIndex($list_index, PCLZIP_OPT_EXTRACT_AS_STRING);
} else {
$filename = substr($fileName, 1);
$list_index = -1;
for ($i = 0; $i < $listCount; ++$i) {
if (strtolower($list[$i]["filename"]) == strtolower($fileName) ||
strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) {
$list_index = $i;
break;
}
}
$extracted = $this->_zip->extractByIndex($list_index, PCLZIP_OPT_EXTRACT_AS_STRING);
}
if ((is_array($extracted)) && ($extracted != 0)) {
$contents = $extracted[0]["content"];
}
return $contents;
}
}

View File

@ -10,6 +10,7 @@
namespace PhpOffice\PhpWord\Shared;
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Settings;
/**
* Zip stream wrapper
@ -90,7 +91,8 @@ class ZipStreamWrapper
}
// Open archive
$this->_archive = new \ZipArchive();
$zipClass = Settings::getZipClass();
$this->_archive = new $zipClass();
$this->_archive->open($url['host']);
$this->_fileNameInArchive = $url['fragment'];

View File

@ -479,8 +479,8 @@ class Font
/**
* Set background color
*
* @param string $pValue
* @return PHPWord_Style_Font
* @param string $pValue
* @return $this
*/
public function setBgColor($pValue = null)
{

View File

@ -57,7 +57,7 @@ class Row
* Set tblHeader
*
* @param boolean $pValue
* @return PHPWord_Style_Row
* @return $this
*/
public function setTblHeader($pValue = false)
{
@ -82,7 +82,7 @@ class Row
* Set cantSplit
*
* @param boolean $pValue
* @return PHPWord_Style_Row
* @return $this
*/
public function setCantSplit($pValue = false)
{
@ -107,7 +107,7 @@ class Row
* Set exactHeight
*
* @param bool $pValue
* @return PHPWord_Style_Row
* @return $this
*/
public function setExactHeight($pValue = false)
{

View File

@ -10,6 +10,7 @@
namespace PhpOffice\PhpWord;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\TOC as TOCStyle;
/**
* Table of contents
@ -26,14 +27,14 @@ class TOC
/**
* TOC style
*
* @var PhpOffice\PhpWord\Style\TOC
* @var TOCStyle
*/
private static $_styleTOC;
/**
* Font style
*
* @var PhpOffice\PhpWord\Style\Font|array|string
* @var Font|array|string
*/
private static $_styleFont;
@ -60,7 +61,7 @@ class TOC
*/
public function __construct($styleFont = null, $styleTOC = null)
{
self::$_styleTOC = new \PhpOffice\PhpWord\Style\TOC();
self::$_styleTOC = new TOCStyle();
if (!is_null($styleTOC) && is_array($styleTOC)) {
foreach ($styleTOC as $key => $value) {
@ -122,7 +123,7 @@ class TOC
/**
* Get TOC Style
*
* @return \PhpOffice\PhpWord\Style\TOC
* @return TOCStyle
*/
public static function getStyleTOC()
{
@ -132,7 +133,7 @@ class TOC
/**
* Get Font Style
*
* @return \PhpOffice\PhpWord\Style\Font
* @return Font
*/
public static function getStyleFont()
{

View File

@ -10,6 +10,7 @@
namespace PhpOffice\PhpWord;
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Shared\String;
/**
@ -20,7 +21,7 @@ class Template
/**
* ZipArchive object
*
* @var \ZipArchive
* @var mixed
*/
private $_objZip;
@ -57,7 +58,8 @@ class Template
throw new Exception("Could not copy the template from {$strFilename} to {$this->_tempFileName}.");
}
$this->_objZip = new \ZipArchive();
$zipClass = Settings::getZipClass();
$this->_objZip = new $zipClass();
$this->_objZip->open($this->_tempFileName);
$this->_documentXML = $this->_objZip->getFromName('word/document.xml');

View File

@ -12,6 +12,7 @@ namespace PhpOffice\PhpWord\Writer;
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\HashTable;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Writer\ODText\Content;
use PhpOffice\PhpWord\Writer\ODText\Manifest;
use PhpOffice\PhpWord\Writer\ODText\Meta;
@ -26,13 +27,13 @@ class ODText extends Writer implements IWriter
/**
* Private unique PHPWord_Worksheet_BaseDrawing HashTable
*
* @var \PhpOffice\PhpWord\HashTable
* @var HashTable
*/
private $drawingHashTable;
/**
* Create new ODText writer
* @param \PhpOffice\PhpWord\PhpWord $phpWord
* @param PhpWord $phpWord
*/
public function __construct(PhpWord $phpWord = null)
{
@ -57,7 +58,7 @@ class ODText extends Writer implements IWriter
* Save PhpWord to file
*
* @param string $pFilename
* @throws \PhpOffice\PhpWord\Exceptions\Exception
* @throws Exception
*/
public function save($pFilename = null)
{
@ -65,11 +66,23 @@ class ODText extends Writer implements IWriter
$pFilename = $this->getTempFile($pFilename);
// Create new ZIP file and open it for writing
$objZip = new \ZipArchive();
$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, \ZipArchive::OVERWRITE) !== true) {
if ($objZip->open($pFilename, \ZipArchive::CREATE) !== true) {
if ($objZip->open($pFilename, $zipOverWrite) !== true) {
if ($objZip->open($pFilename, $zipCreate) !== true) {
throw new Exception("Could not open " . $pFilename . " for writing.");
}
}
@ -101,7 +114,8 @@ class ODText extends Writer implements IWriter
$imagePath = substr($imagePath, 6);
$imagePathSplitted = explode('#', $imagePath);
$imageZip = new \ZipArchive();
$zipClass = Settings::getZipClass();
$imageZip = new $zipClass();
$imageZip->open($imagePathSplitted[0]);
$imageContents = $imageZip->getFromName($imagePathSplitted[1]);
$imageZip->close();
@ -139,7 +153,7 @@ class ODText extends Writer implements IWriter
/**
* Get PHPWord_Worksheet_BaseDrawing HashTable
*
* @return \PhpOffice\PhpWord\HashTable
* @return HashTable
*/
public function getDrawingHashTable()
{

View File

@ -35,7 +35,7 @@ class Content extends WriterPart
/**
* Write content file to XML format
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
* @param PhpWord $phpWord
* @return string XML Output
*/
public function writeContent(PhpWord $phpWord = null)
@ -126,7 +126,7 @@ class Content extends WriterPart
$numFonts = 0;
if (count($styles) > 0) {
foreach ($styles as $styleName => $style) {
// PhpOffice\PhpWord\Style\Font
// Font
if ($style instanceof Font) {
$numFonts++;
$name = $style->getName();
@ -158,7 +158,7 @@ class Content extends WriterPart
if (preg_match('#^T[0-9]+$#', $styleName) != 0
|| preg_match('#^P[0-9]+$#', $styleName) != 0
) {
// PhpOffice\PhpWord\Style\Font
// Font
if ($style instanceof Font) {
$xmlWriter->startElement('style:style');
$xmlWriter->writeAttribute('style:name', $styleName);
@ -244,11 +244,11 @@ class Content extends WriterPart
foreach ($_elements as $element) {
if ($element instanceof Text) {
$this->_writeText($xmlWriter, $element);
$this->writeText($xmlWriter, $element);
} elseif ($element instanceof TextRun) {
$this->_writeTextRun($xmlWriter, $element);
$this->writeTextRun($xmlWriter, $element);
} elseif ($element instanceof TextBreak) {
$this->_writeTextBreak($xmlWriter);
$this->writeTextBreak($xmlWriter);
} elseif ($element instanceof Link) {
$this->writeUnsupportedElement($xmlWriter, 'Link');
} elseif ($element instanceof Title) {
@ -271,9 +271,9 @@ class Content extends WriterPart
}
if ($pSection == $countSections) {
$this->_writeEndSection($xmlWriter, $section);
$this->writeEndSection($xmlWriter, $section);
} else {
$this->_writeSection($xmlWriter, $section);
$this->writeSection($xmlWriter, $section);
}
}
}
@ -288,11 +288,11 @@ class Content extends WriterPart
/**
* Write text
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Section\Text $text
* @param XMLWriter $xmlWriter
* @param Text $text
* @param bool $withoutP
*/
protected function _writeText(XMLWriter $xmlWriter, Text $text, $withoutP = false)
protected function writeText(XMLWriter $xmlWriter, Text $text, $withoutP = false)
{
$styleFont = $text->getFontStyle();
$styleParagraph = $text->getParagraphStyle();
@ -336,18 +336,18 @@ class Content extends WriterPart
/**
* Write TextRun section
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Section\TextRun $textrun
* @param XMLWriter $xmlWriter
* @param TextRun $textrun
* @todo Enable all other section types
*/
protected function _writeTextRun(XMLWriter $xmlWriter, TextRun $textrun)
protected function writeTextRun(XMLWriter $xmlWriter, TextRun $textrun)
{
$elements = $textrun->getElements();
$xmlWriter->startElement('text:p');
if (count($elements) > 0) {
foreach ($elements as $element) {
if ($element instanceof Text) {
$this->_writeText($xmlWriter, $element, true);
$this->writeText($xmlWriter, $element, true);
}
}
}
@ -357,9 +357,9 @@ class Content extends WriterPart
/**
* Write TextBreak
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param XMLWriter $xmlWriter
*/
protected function _writeTextBreak(XMLWriter $xmlWriter = null)
protected function writeTextBreak(XMLWriter $xmlWriter = null)
{
$xmlWriter->startElement('text:p');
$xmlWriter->writeAttribute('text:style-name', 'Standard');
@ -370,20 +370,20 @@ class Content extends WriterPart
/**
* Write end section
*
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param PhpOffice\PhpWord\Section $section
* @param XMLWriter $xmlWriter
* @param Section $section
*/
private function _writeEndSection(XMLWriter $xmlWriter = null, Section $section = null)
private function writeEndSection(XMLWriter $xmlWriter = null, Section $section = null)
{
}
/**
* Write section
*
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param PhpOffice\PhpWord\Section $section
* @param XMLWriter $xmlWriter
* @param Section $section
*/
private function _writeSection(XMLWriter $xmlWriter = null, Section $section = null)
private function writeSection(XMLWriter $xmlWriter = null, Section $section = null)
{
}
// @codeCoverageIgnoreEnd
@ -391,7 +391,7 @@ class Content extends WriterPart
/**
* Write unsupported element
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param XMLWriter $xmlWriter
* @param string $element
*/
private function writeUnsupportedElement($xmlWriter, $element)

View File

@ -21,7 +21,7 @@ class Manifest extends WriterPart
/**
* Write Manifest file to XML format
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
* @param PhpWord $phpWord
* @return string XML Output
*/
public function writeManifest(PhpWord $phpWord = null)
@ -64,7 +64,7 @@ class Manifest extends WriterPart
for ($i = 0; $i < $this->getParentWriter()->getDrawingHashTable()->count(); ++$i) {
if ($this->getParentWriter()->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_Drawing) {
$extension = strtolower($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getExtension());
$mimeType = $this->_getImageMimeType($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getPath());
$mimeType = $this->getImageMimeType($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getPath());
$xmlWriter->startElement('manifest:file-entry');
$xmlWriter->writeAttribute('manifest:media-type', $mimeType);
@ -97,9 +97,9 @@ class Manifest extends WriterPart
*
* @param string $pFile Filename
* @return string Mime Type
* @throws \PhpOffice\PhpWord\Exceptions\Exception
* @throws Exception
*/
private function _getImageMimeType($pFile = '')
private function getImageMimeType($pFile = '')
{
if (file_exists($pFile)) {
$image = getimagesize($pFile);

View File

@ -20,7 +20,7 @@ class Meta extends WriterPart
/**
* Write Meta file to XML format
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
* @param PhpWord $phpWord
* @return string XML Output
*/
public function writeMeta(PhpWord $phpWord = null)

View File

@ -19,7 +19,7 @@ class Mimetype extends WriterPart
/**
* Write Mimetype to Text format
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
* @param PhpWord $phpWord
* @return string Text Output
*/
public function writeMimetype(PhpWord $phpWord = null)

View File

@ -24,7 +24,7 @@ class Styles extends WriterPart
/**
* Write Styles file to XML format
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
* @param PhpWord $phpWord
* @return string XML Output
*/
public function writeStyles(PhpWord $phpWord = null)
@ -73,7 +73,7 @@ class Styles extends WriterPart
$numFonts = 0;
if (count($styles) > 0) {
foreach ($styles as $styleName => $style) {
// PhpOffice\PhpWord\Style\Font
// Font
if ($style instanceof Font) {
$numFonts++;
$name = $style->getName();
@ -144,7 +144,7 @@ class Styles extends WriterPart
if (preg_match('#^T[0-9]+$#', $styleName) == 0
&& preg_match('#^P[0-9]+$#', $styleName) == 0
) {
// PhpOffice\PhpWord\Style\Font
// Font
if ($style instanceof Font) {
// style:style
$xmlWriter->startElement('style:style');
@ -168,7 +168,7 @@ class Styles extends WriterPart
$xmlWriter->endElement();
$xmlWriter->endElement();
} elseif ($style instanceof Paragraph) {
// PhpOffice\PhpWord\Style\Paragraph
// Paragraph
// style:style
$xmlWriter->startElement('style:style');
$xmlWriter->writeAttribute('style:name', $styleName);
@ -183,7 +183,7 @@ class Styles extends WriterPart
$xmlWriter->endElement();
} elseif ($style instanceof Table) {
// PhpOffice\PhpWord\Style\Table
// Table
}
}
}

View File

@ -36,7 +36,7 @@ class RTF extends Writer implements IWriter
/**
* Private unique PHPWord_Worksheet_BaseDrawing HashTable
*
* @var \PhpOffice\PhpWord\HashTable
* @var HashTable
*/
private $drawingHashTable;
@ -63,7 +63,7 @@ class RTF extends Writer implements IWriter
/**
* Create new RTF writer
* @param \PhpOffice\PhpWord\PhpWord $phpWord
* @param PhpWord $phpWord
*/
public function __construct(PhpWord $phpWord = null)
{
@ -78,7 +78,7 @@ class RTF extends Writer implements IWriter
* Save PhpWord to file
*
* @param string $pFilename
* @throws \PhpOffice\PhpWord\Exceptions\Exception
* @throws Exception
*/
public function save($pFilename = null)
{
@ -98,7 +98,7 @@ class RTF extends Writer implements IWriter
/**
* Get PHPWord_Worksheet_BaseDrawing HashTable
*
* @return \PhpOffice\PhpWord\HashTable
* @return HashTable
*/
public function getDrawingHashTable()
{
@ -179,10 +179,9 @@ class RTF extends Writer implements IWriter
// Browse styles
$styles = Style::getStyles();
$numPStyles = 0;
if (count($styles) > 0) {
foreach ($styles as $styleName => $style) {
// PhpOffice\PhpWord\Style\Font
// Font
if ($style instanceof Font) {
if (in_array($style->getName(), $arrFonts) == false) {
$arrFonts[] = $style->getName();
@ -232,7 +231,6 @@ class RTF extends Writer implements IWriter
// Browse styles
$styles = Style::getStyles();
$numPStyles = 0;
if (count($styles) > 0) {
foreach ($styles as $styleName => $style) {
// Font

View File

@ -13,6 +13,7 @@ use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Footnote;
use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Writer\Word2007\ContentTypes;
use PhpOffice\PhpWord\Writer\Word2007\DocProps;
use PhpOffice\PhpWord\Writer\Word2007\Document;
@ -34,19 +35,19 @@ class Word2007 extends Writer implements IWriter
*
* @var array
*/
private $_imageTypes = array();
private $imageTypes = array();
/**
* Types of objects
*
* @var array
*/
private $_objectTypes = array();
private $objectTypes = array();
/**
* Create new Word2007 writer
*
* @param PhpOffice\PhpWord\PhpWord
* @param PhpWord
*/
public function __construct(PhpWord $phpWord = null)
{
@ -80,11 +81,23 @@ class Word2007 extends Writer implements IWriter
$pFilename = $this->getTempFile($pFilename);
// Create new ZIP file and open it for writing
$objZip = new \ZipArchive();
$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, \ZipArchive::OVERWRITE) !== true) {
if ($objZip->open($pFilename, \ZipArchive::CREATE) !== true) {
if ($objZip->open($pFilename, $zipOverWrite) !== true) {
if ($objZip->open($pFilename, $zipCreate) !== true) {
throw new Exception("Could not open " . $pFilename . " for writing.");
}
}
@ -167,8 +180,8 @@ class Word2007 extends Writer implements IWriter
$objZip->addFromString(
'[Content_Types].xml',
$this->getWriterPart('contenttypes')->writeContentTypes(
$this->_imageTypes,
$this->_objectTypes,
$this->imageTypes,
$this->objectTypes,
$_cHdrs,
$footers
)
@ -235,12 +248,12 @@ class Word2007 extends Writer implements IWriter
if ($imageExtension === 'jpeg') {
$imageExtension = 'jpg';
}
if (!in_array($imageType, $this->_imageTypes)) {
$this->_imageTypes[$imageExtension] = $imageType;
if (!in_array($imageType, $this->imageTypes)) {
$this->imageTypes[$imageExtension] = $imageType;
}
} else {
if (!in_array($extension, $this->_objectTypes)) {
$this->_objectTypes[] = $extension;
if (!in_array($extension, $this->objectTypes)) {
$this->objectTypes[] = $extension;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -19,12 +19,12 @@ class ContentTypes extends WriterPart
{
/**
* Write [Content_Types].xml
* @param array $_imageTypes
* @param array $_objectTypes
* @param array $imageTypes
* @param array $objectTypes
* @param int $_cHdrs
* @param array $footers
*/
public function writeContentTypes($_imageTypes, $_objectTypes, $_cHdrs, $footers)
public function writeContentTypes($imageTypes, $objectTypes, $_cHdrs, $footers)
{
// Create XML writer
$xmlWriter = $this->getXmlWriter();
@ -37,27 +37,27 @@ class ContentTypes extends WriterPart
$xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/content-types');
// Rels
$this->_writeDefaultContentType(
$this->writeDefaultContentType(
$xmlWriter,
'rels',
'application/vnd.openxmlformats-package.relationships+xml'
);
// XML
$this->_writeDefaultContentType(
$this->writeDefaultContentType(
$xmlWriter,
'xml',
'application/xml'
);
// Add media content-types
foreach ($_imageTypes as $key => $value) {
$this->_writeDefaultContentType($xmlWriter, $key, $value);
foreach ($imageTypes as $key => $value) {
$this->writeDefaultContentType($xmlWriter, $key, $value);
}
// Add embedding content-types
if (count($_objectTypes) > 0) {
$this->_writeDefaultContentType(
if (count($objectTypes) > 0) {
$this->writeDefaultContentType(
$xmlWriter,
'bin',
'application/vnd.openxmlformats-officedocument.oleObject'
@ -65,76 +65,76 @@ class ContentTypes extends WriterPart
}
// DocProps
$this->_writeOverrideContentType(
$this->writeOverrideContentType(
$xmlWriter,
'/docProps/app.xml',
'application/vnd.openxmlformats-officedocument.extended-properties+xml'
);
$this->_writeOverrideContentType(
$this->writeOverrideContentType(
$xmlWriter,
'/docProps/core.xml',
'application/vnd.openxmlformats-package.core-properties+xml'
);
// Document
$this->_writeOverrideContentType(
$this->writeOverrideContentType(
$xmlWriter,
'/word/document.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml'
);
// Styles
$this->_writeOverrideContentType(
$this->writeOverrideContentType(
$xmlWriter,
'/word/styles.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml'
);
// Numbering
$this->_writeOverrideContentType(
$this->writeOverrideContentType(
$xmlWriter,
'/word/numbering.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml'
);
// Settings
$this->_writeOverrideContentType(
$this->writeOverrideContentType(
$xmlWriter,
'/word/settings.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml'
);
// Theme1
$this->_writeOverrideContentType(
$this->writeOverrideContentType(
$xmlWriter,
'/word/theme/theme1.xml',
'application/vnd.openxmlformats-officedocument.theme+xml'
);
// WebSettings
$this->_writeOverrideContentType(
$this->writeOverrideContentType(
$xmlWriter,
'/word/webSettings.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml'
);
// Font Table
$this->_writeOverrideContentType(
$this->writeOverrideContentType(
$xmlWriter,
'/word/fontTable.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml'
);
// Footnotes
$this->_writeOverrideContentType(
$this->writeOverrideContentType(
$xmlWriter,
'/word/footnotes.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml'
);
for ($i = 1; $i <= $_cHdrs; $i++) {
$this->_writeOverrideContentType(
$this->writeOverrideContentType(
$xmlWriter,
'/word/header' . $i . '.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml'
@ -143,7 +143,7 @@ class ContentTypes extends WriterPart
for ($i = 1; $i <= count($footers); $i++) {
if (!is_null($footers[$i])) {
$this->_writeOverrideContentType(
$this->writeOverrideContentType(
$xmlWriter,
'/word/footer' . $i . '.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml'
@ -158,32 +158,15 @@ class ContentTypes extends WriterPart
return $xmlWriter->getData();
}
/**
* Get image mime type
*
* @param string $pFile Filename
* @return string Mime Type
* @throws \PhpOffice\PhpWord\Exceptions\Exception
*/
private function _getImageMimeType($pFile = '')
{
if (file_exists($pFile)) {
$image = getimagesize($pFile);
return image_type_to_mime_type($image[2]);
} else {
throw new Exception("File $pFile does not exist");
}
}
/**
* Write Default XML element
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter XML Writer
* @param XMLWriter $xmlWriter XML Writer
* @param string $pPartname Part name
* @param string $pContentType Content type
* @throws \PhpOffice\PhpWord\Exceptions\Exception
* @throws Exception
*/
private function _writeDefaultContentType(XMLWriter $xmlWriter = null, $pPartname = '', $pContentType = '')
private function writeDefaultContentType(XMLWriter $xmlWriter = null, $pPartname = '', $pContentType = '')
{
if ($pPartname != '' && $pContentType != '') {
// Write content type
@ -199,12 +182,12 @@ class ContentTypes extends WriterPart
/**
* Write Override XML element
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param XMLWriter $xmlWriter
* @param string $pPartname Part name
* @param string $pContentType Content type
* @throws \PhpOffice\PhpWord\Exceptions\Exception
* @throws Exception
*/
private function _writeOverrideContentType(XMLWriter $xmlWriter = null, $pPartname = '', $pContentType = '')
private function writeOverrideContentType(XMLWriter $xmlWriter = null, $pPartname = '', $pContentType = '')
{
if ($pPartname != '' && $pContentType != '') {
// Write content type
@ -216,4 +199,21 @@ class ContentTypes extends WriterPart
throw new Exception("Invalid parameters passed.");
}
}
/**
* Get image mime type
*
* @param string $pFile Filename
* @return string Mime Type
* @throws Exception
*/
private function getImageMimeType($pFile = '')
{
if (file_exists($pFile)) {
$image = getimagesize($pFile);
return image_type_to_mime_type($image[2]);
} else {
throw new Exception("File $pFile does not exist");
}
}
}

View File

@ -110,7 +110,7 @@ class DocProps extends WriterPart
/**
* Write docProps/core.xml
*
* @param PhpOffice\PhpWord\PhpWord $phpWord
* @param PhpWord $phpWord
*/
public function writeDocPropsCore(PhpWord $phpWord = null)
{

View File

@ -36,7 +36,7 @@ class Document extends Base
/**
* Write word/document.xml
*
* @param PhpOffice\PhpWord\PhpWord $phpWord
* @param PhpWord $phpWord
*/
public function writeDocument(PhpWord $phpWord = null)
{
@ -72,38 +72,38 @@ class Document extends Base
$_elements = $section->getElements();
foreach ($_elements as $element) {
if ($element instanceof Text) {
$this->_writeText($xmlWriter, $element);
$this->writeText($xmlWriter, $element);
} elseif ($element instanceof TextRun) {
$this->_writeTextRun($xmlWriter, $element);
$this->writeTextRun($xmlWriter, $element);
} elseif ($element instanceof Link) {
$this->_writeLink($xmlWriter, $element);
$this->writeLink($xmlWriter, $element);
} elseif ($element instanceof Title) {
$this->_writeTitle($xmlWriter, $element);
$this->writeTitle($xmlWriter, $element);
} elseif ($element instanceof TextBreak) {
$this->_writeTextBreak($xmlWriter, $element);
$this->writeTextBreak($xmlWriter, $element);
} elseif ($element instanceof PageBreak) {
$this->_writePageBreak($xmlWriter);
$this->writePageBreak($xmlWriter);
} elseif ($element instanceof Table) {
$this->_writeTable($xmlWriter, $element);
$this->writeTable($xmlWriter, $element);
} elseif ($element instanceof ListItem) {
$this->_writeListItem($xmlWriter, $element);
$this->writeListItem($xmlWriter, $element);
} elseif ($element instanceof Image) {
$this->_writeImage($xmlWriter, $element);
$this->writeImage($xmlWriter, $element);
} elseif ($element instanceof Object) {
$this->_writeObject($xmlWriter, $element);
$this->writeObject($xmlWriter, $element);
} elseif ($element instanceof TOC) {
$this->_writeTOC($xmlWriter);
$this->writeTOC($xmlWriter);
} elseif ($element instanceof Footnote) {
$this->_writeFootnote($xmlWriter, $element);
$this->writeFootnote($xmlWriter, $element);
} elseif ($element instanceof CheckBox) {
$this->_writeCheckBox($xmlWriter, $element);
$this->writeCheckBox($xmlWriter, $element);
}
}
if ($pSection == $countSections) {
$this->_writeEndSection($xmlWriter, $section);
$this->writeEndSection($xmlWriter, $section);
} else {
$this->_writeSection($xmlWriter, $section);
$this->writeSection($xmlWriter, $section);
}
}
}
@ -118,14 +118,14 @@ class Document extends Base
/**
* Write begin section
*
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param PhpOffice\PhpWord\Section $section
* @param XMLWriter $xmlWriter
* @param Section $section
*/
private function _writeSection(XMLWriter $xmlWriter, Section $section)
private function writeSection(XMLWriter $xmlWriter, Section $section)
{
$xmlWriter->startElement('w:p');
$xmlWriter->startElement('w:pPr');
$this->_writeEndSection($xmlWriter, $section, 3);
$this->writeEndSection($xmlWriter, $section, 3);
$xmlWriter->endElement();
$xmlWriter->endElement();
}
@ -133,10 +133,10 @@ class Document extends Base
/**
* Write end section
*
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param PhpOffice\PhpWord\Section $section
* @param XMLWriter $xmlWriter
* @param Section $section
*/
private function _writeEndSection(XMLWriter $xmlWriter, Section $section)
private function writeEndSection(XMLWriter $xmlWriter, Section $section)
{
$settings = $section->getSettings();
$_headers = $section->getHeaders();
@ -272,9 +272,9 @@ class Document extends Base
/**
* Write page break element
*
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param XMLWriter $xmlWriter
*/
private function _writePageBreak(XMLWriter $xmlWriter)
private function writePageBreak(XMLWriter $xmlWriter)
{
$xmlWriter->startElement('w:p');
$xmlWriter->startElement('w:r');
@ -285,122 +285,12 @@ class Document extends Base
$xmlWriter->endElement();
}
/**
* Write list item element
*
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param PhpOffice\PhpWord\Section\ListItem $listItem
*/
public function _writeListItem(XMLWriter $xmlWriter, ListItem $listItem)
{
$textObject = $listItem->getTextObject();
$text = $textObject->getText();
$styleParagraph = $textObject->getParagraphStyle();
$SpIsObject = ($styleParagraph instanceof Paragraph) ? true : false;
$depth = $listItem->getDepth();
$listType = $listItem->getStyle()->getListType();
$xmlWriter->startElement('w:p');
$xmlWriter->startElement('w:pPr');
if ($SpIsObject) {
$this->_writeParagraphStyle($xmlWriter, $styleParagraph, true);
} elseif (!$SpIsObject && !is_null($styleParagraph)) {
$xmlWriter->startElement('w:pStyle');
$xmlWriter->writeAttribute('w:val', $styleParagraph);
$xmlWriter->endElement();
}
$xmlWriter->startElement('w:numPr');
$xmlWriter->startElement('w:ilvl');
$xmlWriter->writeAttribute('w:val', $depth);
$xmlWriter->endElement();
$xmlWriter->startElement('w:numId');
$xmlWriter->writeAttribute('w:val', $listType);
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->endElement();
$this->_writeText($xmlWriter, $textObject, true);
$xmlWriter->endElement();
}
/**
* Write object element
*
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param PhpOffice\PhpWord\Section\Object $object
*/
protected function _writeObject(XMLWriter $xmlWriter, Object $object)
{
$rIdObject = $object->getRelationId();
$rIdImage = $object->getImageRelationId();
$shapeId = md5($rIdObject . '_' . $rIdImage);
$objectId = $object->getObjectId();
$style = $object->getStyle();
$width = $style->getWidth();
$height = $style->getHeight();
$align = $style->getAlign();
$xmlWriter->startElement('w:p');
if (!is_null($align)) {
$xmlWriter->startElement('w:pPr');
$xmlWriter->startElement('w:jc');
$xmlWriter->writeAttribute('w:val', $align);
$xmlWriter->endElement();
$xmlWriter->endElement();
}
$xmlWriter->startElement('w:r');
$xmlWriter->startElement('w:object');
$xmlWriter->writeAttribute('w:dxaOrig', '249');
$xmlWriter->writeAttribute('w:dyaOrig', '160');
$xmlWriter->startElement('v:shape');
$xmlWriter->writeAttribute('id', $shapeId);
$xmlWriter->writeAttribute('type', '#_x0000_t75');
$xmlWriter->writeAttribute('style', 'width:104px;height:67px');
$xmlWriter->writeAttribute('o:ole', '');
$xmlWriter->startElement('v:imagedata');
$xmlWriter->writeAttribute('r:id', 'rId' . $rIdImage);
$xmlWriter->writeAttribute('o:title', '');
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->startElement('o:OLEObject');
$xmlWriter->writeAttribute('Type', 'Embed');
$xmlWriter->writeAttribute('ProgID', 'Package');
$xmlWriter->writeAttribute('ShapeID', $shapeId);
$xmlWriter->writeAttribute('DrawAspect', 'Icon');
$xmlWriter->writeAttribute('ObjectID', '_' . $objectId);
$xmlWriter->writeAttribute('r:id', 'rId' . $rIdObject);
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->endElement(); // w:r
$xmlWriter->endElement(); // w:p
}
/**
* Write TOC element
*
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param XMLWriter $xmlWriter
*/
private function _writeTOC(XMLWriter $xmlWriter)
private function writeTOC(XMLWriter $xmlWriter)
{
$titles = TOC::getTitles();
$styleFont = TOC::getStyleFont();
@ -421,7 +311,7 @@ class Document extends Base
$xmlWriter->startElement('w:pPr');
if ($isObject && !is_null($styleFont->getParagraphStyle())) {
$this->_writeParagraphStyle($xmlWriter, $styleFont->getParagraphStyle());
$this->writeParagraphStyle($xmlWriter, $styleFont->getParagraphStyle());
}
if ($indent > 0) {
@ -479,7 +369,7 @@ class Document extends Base
$xmlWriter->startElement('w:r');
if ($isObject) {
$this->_writeTextStyle($xmlWriter, $styleFont);
$this->writeFontStyle($xmlWriter, $styleFont);
}
$xmlWriter->startElement('w:t');

View File

@ -15,7 +15,7 @@ use PhpOffice\PhpWord\Shared\XMLWriter;
/**
* Word2007 document rels part writer
*/
class DocumentRels extends WriterPart
class DocumentRels extends Base
{
/**
* Write word/_rels/document.xml.rels
@ -35,7 +35,7 @@ class DocumentRels extends WriterPart
$xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
// Relationship word/document.xml
$this->_writeRelationship(
$this->writeRelationship(
$xmlWriter,
1,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles',
@ -43,7 +43,7 @@ class DocumentRels extends WriterPart
);
// Relationship word/numbering.xml
$this->_writeRelationship(
$this->writeRelationship(
$xmlWriter,
2,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering',
@ -51,7 +51,7 @@ class DocumentRels extends WriterPart
);
// Relationship word/settings.xml
$this->_writeRelationship(
$this->writeRelationship(
$xmlWriter,
3,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings',
@ -59,7 +59,7 @@ class DocumentRels extends WriterPart
);
// Relationship word/settings.xml
$this->_writeRelationship(
$this->writeRelationship(
$xmlWriter,
4,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme',
@ -67,7 +67,7 @@ class DocumentRels extends WriterPart
);
// Relationship word/settings.xml
$this->_writeRelationship(
$this->writeRelationship(
$xmlWriter,
5,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings',
@ -75,7 +75,7 @@ class DocumentRels extends WriterPart
);
// Relationship word/settings.xml
$this->_writeRelationship(
$this->writeRelationship(
$xmlWriter,
6,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable',
@ -89,7 +89,7 @@ class DocumentRels extends WriterPart
$relationId = $relation['rID'];
$targetMode = ($relationType == 'hyperlink') ? 'External' : '';
$this->_writeRelationship(
$this->writeRelationship(
$xmlWriter,
$relationId,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType,
@ -128,7 +128,7 @@ class DocumentRels extends WriterPart
$relationName = $relation['target'];
$relationId = $relation['rID'];
$this->_writeRelationship(
$this->writeRelationship(
$xmlWriter,
$relationId,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType,
@ -142,36 +142,4 @@ class DocumentRels extends WriterPart
// Return
return $xmlWriter->getData();
}
/**
* Write individual rels entry
*
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param int $pId Relationship ID
* @param string $pType Relationship type
* @param string $pTarget Relationship target
* @param string $pTargetMode Relationship target mode
*/
private function _writeRelationship(XMLWriter $xmlWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '')
{
if ($pType != '' && $pTarget != '') {
if (strpos($pId, 'rId') === false) {
$pId = 'rId' . $pId;
}
// Write relationship
$xmlWriter->startElement('Relationship');
$xmlWriter->writeAttribute('Id', $pId);
$xmlWriter->writeAttribute('Type', $pType);
$xmlWriter->writeAttribute('Target', $pTarget);
if ($pTargetMode != '') {
$xmlWriter->writeAttribute('TargetMode', $pTargetMode);
}
$xmlWriter->endElement();
} else {
throw new Exception("Invalid parameters passed.");
}
}
}

View File

@ -15,6 +15,7 @@ use PhpOffice\PhpWord\Section\Table;
use PhpOffice\PhpWord\Section\Text;
use PhpOffice\PhpWord\Section\TextBreak;
use PhpOffice\PhpWord\Section\TextRun;
use PhpOffice\PhpWord\Section\Footer as FooterElement;
use PhpOffice\PhpWord\Shared\XMLWriter;
/**
@ -25,9 +26,9 @@ class Footer extends Base
/**
* Write word/footnotes.xml
*
* @param PhpOffice\PhpWord\Section\Footer $footer
* @param FooterElement $footer
*/
public function writeFooter(\PhpOffice\PhpWord\Section\Footer $footer)
public function writeFooter(FooterElement $footer)
{
// Create XML writer
$xmlWriter = $this->getXmlWriter();
@ -50,17 +51,17 @@ class Footer extends Base
foreach ($_elements as $element) {
if ($element instanceof Text) {
$this->_writeText($xmlWriter, $element);
$this->writeText($xmlWriter, $element);
} elseif ($element instanceof TextRun) {
$this->_writeTextRun($xmlWriter, $element);
$this->writeTextRun($xmlWriter, $element);
} elseif ($element instanceof TextBreak) {
$this->_writeTextBreak($xmlWriter, $element);
$this->writeTextBreak($xmlWriter, $element);
} elseif ($element instanceof Table) {
$this->_writeTable($xmlWriter, $element);
$this->writeTable($xmlWriter, $element);
} elseif ($element instanceof Image) {
$this->_writeImage($xmlWriter, $element);
$this->writeImage($xmlWriter, $element);
} elseif ($element instanceof PreserveText) {
$this->_writePreserveText($xmlWriter, $element);
$this->writePreserveText($xmlWriter, $element);
}
}

View File

@ -77,26 +77,18 @@ class Footnotes extends Base
/**
* Write footnote content, overrides method in parent class
*
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param PhpOffice\PhpWord\Section\Footnote $footnote
* @param XMLWriter $xmlWriter
* @param Footnote $footnote
* @param boolean $withoutP
*/
private function writeFootnote(XMLWriter $xmlWriter, Footnote $footnote)
protected function writeFootnote(XMLWriter $xmlWriter, Footnote $footnote, $withoutP = false)
{
$xmlWriter->startElement('w:footnote');
$xmlWriter->writeAttribute('w:id', $footnote->getReferenceId());
$xmlWriter->startElement('w:p');
// Paragraph style
$paragraphStyle = $footnote->getParagraphStyle();
$spIsObject = ($paragraphStyle instanceof Paragraph) ? true : false;
if ($spIsObject) {
$this->_writeParagraphStyle($xmlWriter, $paragraphStyle);
} elseif (!$spIsObject && !is_null($paragraphStyle)) {
$xmlWriter->startElement('w:pPr');
$xmlWriter->startElement('w:pStyle');
$xmlWriter->writeAttribute('w:val', $paragraphStyle);
$xmlWriter->endElement();
$xmlWriter->endElement();
}
$styleParagraph = $footnote->getParagraphStyle();
$this->writeInlineParagraphStyle($xmlWriter, $styleParagraph);
// Reference symbol
$xmlWriter->startElement('w:r');
$xmlWriter->startElement('w:rPr');
@ -118,9 +110,9 @@ class Footnotes extends Base
if (count($elements) > 0) {
foreach ($elements as $element) {
if ($element instanceof Text) {
$this->_writeText($xmlWriter, $element, true);
$this->writeText($xmlWriter, $element, true);
} elseif ($element instanceof Link) {
$this->_writeLink($xmlWriter, $element, true);
$this->writeLink($xmlWriter, $element, true);
} elseif ($element instanceof TextBreak) {
$xmlWriter->writeElement('w:br');
}

View File

@ -15,7 +15,7 @@ use PhpOffice\PhpWord\Shared\XMLWriter;
/**
* Word2007 footnotes rel part writer
*/
class FootnotesRels extends WriterPart
class FootnotesRels extends Base
{
/**
* Write word/_rels/footnotes.xml.rels
@ -41,7 +41,7 @@ class FootnotesRels extends WriterPart
$relationId = $relation['rID'];
$targetMode = ($relationType == 'hyperlink') ? 'External' : '';
$this->_writeRelationship($xmlWriter, $relationId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType, $relationName, $targetMode);
$this->writeRelationship($xmlWriter, $relationId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType, $relationName, $targetMode);
}
$xmlWriter->endElement();
@ -49,36 +49,4 @@ class FootnotesRels extends WriterPart
// Return
return $xmlWriter->getData();
}
/**
* Write individual rels entry
*
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param int $pId Relationship ID
* @param string $pType Relationship type
* @param string $pTarget Relationship target
* @param string $pTargetMode Relationship target mode
*/
private function _writeRelationship(XMLWriter $xmlWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '')
{
if ($pType != '' && $pTarget != '') {
if (strpos($pId, 'rId') === false) {
$pId = 'rId' . $pId;
}
// Write relationship
$xmlWriter->startElement('Relationship');
$xmlWriter->writeAttribute('Id', $pId);
$xmlWriter->writeAttribute('Type', $pType);
$xmlWriter->writeAttribute('Target', $pTarget);
if ($pTargetMode != '') {
$xmlWriter->writeAttribute('TargetMode', $pTargetMode);
}
$xmlWriter->endElement();
} else {
throw new Exception("Invalid parameters passed.");
}
}
}

View File

@ -15,6 +15,7 @@ use PhpOffice\PhpWord\Section\Table;
use PhpOffice\PhpWord\Section\Text;
use PhpOffice\PhpWord\Section\TextBreak;
use PhpOffice\PhpWord\Section\TextRun;
use PhpOffice\PhpWord\Section\Header as HeaderElement;
use PhpOffice\PhpWord\Shared\XMLWriter;
/**
@ -25,9 +26,9 @@ class Header extends Base
/**
* Write word/headerx.xml
*
* @param PhpOffice\PhpWord\Section\Header $header
* @param HeaderElement $header
*/
public function writeHeader(\PhpOffice\PhpWord\Section\Header $header)
public function writeHeader(HeaderElement $header)
{
// Create XML writer
$xmlWriter = $this->getXmlWriter();
@ -51,21 +52,21 @@ class Header extends Base
foreach ($_elements as $element) {
if ($element instanceof Text) {
$this->_writeText($xmlWriter, $element);
$this->writeText($xmlWriter, $element);
} elseif ($element instanceof TextRun) {
$this->_writeTextRun($xmlWriter, $element);
$this->writeTextRun($xmlWriter, $element);
} elseif ($element instanceof TextBreak) {
$this->_writeTextBreak($xmlWriter, $element);
$this->writeTextBreak($xmlWriter, $element);
} elseif ($element instanceof Table) {
$this->_writeTable($xmlWriter, $element);
$this->writeTable($xmlWriter, $element);
} elseif ($element instanceof Image) {
if (!$element->getIsWatermark()) {
$this->_writeImage($xmlWriter, $element);
$this->writeImage($xmlWriter, $element);
} else {
$this->_writeWatermark($xmlWriter, $element);
$this->writeWatermark($xmlWriter, $element);
}
} elseif ($element instanceof PreserveText) {
$this->_writePreserveText($xmlWriter, $element);
$this->writePreserveText($xmlWriter, $element);
}
}

View File

@ -16,12 +16,12 @@ use PhpOffice\PhpWord\Shared\XMLWriter;
/**
* Word2007 rels part writer
*/
class Rels extends WriterPart
class Rels extends Base
{
/**
* Write _rels/.rels
*
* @param PhpOffice\PhpWord\PhpWord $phpWord
* @param PhpWord $phpWord
*/
public function writeRelationships(PhpWord $phpWord = null)
{
@ -38,7 +38,7 @@ class Rels extends WriterPart
$relationId = 1;
// Relationship word/document.xml
$this->_writeRelationship(
$this->writeRelationship(
$xmlWriter,
$relationId,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument',
@ -46,7 +46,7 @@ class Rels extends WriterPart
);
// Relationship docProps/core.xml
$this->_writeRelationship(
$this->writeRelationship(
$xmlWriter,
++$relationId,
'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties',
@ -54,7 +54,7 @@ class Rels extends WriterPart
);
// Relationship docProps/app.xml
$this->_writeRelationship(
$this->writeRelationship(
$xmlWriter,
++$relationId,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties',
@ -65,37 +65,4 @@ class Rels extends WriterPart
return $xmlWriter->getData();
}
/**
* Write Override content type
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param int $pId Relationship ID. rId will be prepended!
* @param string $pType Relationship type
* @param string $pTarget Relationship target
* @param string $pTargetMode Relationship target mode
* @throws \PhpOffice\PhpWord\Exceptions\Exception
*/
private function _writeRelationship(XMLWriter $xmlWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '')
{
if ($pType != '' && $pTarget != '') {
if (strpos($pId, 'rId') === false) {
$pId = 'rId' . $pId;
}
// Write relationship
$xmlWriter->startElement('Relationship');
$xmlWriter->writeAttribute('Id', $pId);
$xmlWriter->writeAttribute('Type', $pType);
$xmlWriter->writeAttribute('Target', $pTarget);
if ($pTargetMode != '') {
$xmlWriter->writeAttribute('TargetMode', $pTargetMode);
}
$xmlWriter->endElement();
} else {
throw new Exception("Invalid parameters passed.");
}
}
}

View File

@ -14,28 +14,20 @@ use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
use PhpOffice\PhpWord\Style\Table;
/**
* Word2007 styles part writer
*/
class Styles extends Base
{
/**
* PhpWord object
*
* @var PhpWord
*/
private $phpWord;
/**
* Write word/styles.xml
*
* @param PhpOffice\PhpWord\PhpWord $phpWord
* @param PhpWord $phpWord
*/
public function writeStyles(PhpWord $phpWord = null)
{
$this->phpWord = $phpWord;
// Create XML writer
$xmlWriter = $this->getXmlWriter();
@ -52,7 +44,7 @@ class Styles extends Base
);
// Write default styles
$styles = Style::getStyles();
$this->writeDefaultStyles($xmlWriter, $styles);
$this->writeDefaultStyles($xmlWriter, $phpWord, $styles);
// Write other styles
if (count($styles) > 0) {
foreach ($styles as $styleName => $style) {
@ -94,10 +86,10 @@ class Styles extends Base
$xmlWriter->startElement('w:basedOn');
$xmlWriter->writeAttribute('w:val', 'Normal');
$xmlWriter->endElement();
$this->_writeParagraphStyle($xmlWriter, $paragraphStyle);
$this->writeParagraphStyle($xmlWriter, $paragraphStyle);
}
$this->_writeTextStyle($xmlWriter, $style);
$this->writeFontStyle($xmlWriter, $style);
$xmlWriter->endElement();
@ -127,10 +119,10 @@ class Styles extends Base
$xmlWriter->endElement();
}
$this->_writeParagraphStyle($xmlWriter, $style);
$this->writeParagraphStyle($xmlWriter, $style);
$xmlWriter->endElement();
} elseif ($style instanceof \PhpOffice\PhpWord\Style\Table) {
} elseif ($style instanceof Table) {
$xmlWriter->startElement('w:style');
$xmlWriter->writeAttribute('w:type', 'table');
$xmlWriter->writeAttribute('w:customStyle', '1');
@ -144,7 +136,7 @@ class Styles extends Base
$xmlWriter->writeAttribute('w:val', '99');
$xmlWriter->endElement();
$this->_writeTableStyle($xmlWriter, $style);
$this->writeTableStyle($xmlWriter, $style);
$xmlWriter->endElement(); // w:style
}
@ -160,13 +152,13 @@ class Styles extends Base
/**
* Write default font and other default styles
*
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param XMLWriter $xmlWriter
* @param array $styles
*/
private function writeDefaultStyles(XMLWriter $xmlWriter, $styles)
private function writeDefaultStyles(XMLWriter $xmlWriter, PhpWord $phpWord, $styles)
{
$fontName = $this->phpWord->getDefaultFontName();
$fontSize = $this->phpWord->getDefaultFontSize();
$fontName = $phpWord->getDefaultFontName();
$fontSize = $phpWord->getDefaultFontSize();
// Default font
$xmlWriter->startElement('w:docDefaults');
@ -197,7 +189,7 @@ class Styles extends Base
$xmlWriter->writeAttribute('w:val', 'Normal');
$xmlWriter->endElement(); // w:name
if (array_key_exists('Normal', $styles)) {
$this->_writeParagraphStyle($xmlWriter, $styles['Normal']);
$this->writeParagraphStyle($xmlWriter, $styles['Normal']);
}
$xmlWriter->endElement(); // w:style

View File

@ -22,7 +22,7 @@ abstract class Writer implements IWriter
/**
* PHPWord object
*
* @var PhpOffice\PhpWord\PhpWord
* @var PhpWord
*/
protected $phpWord = null;

View File

@ -0,0 +1,38 @@
<?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\Tests\Shared;
use PhpOffice\PhpWord\Shared\ZipArchive;
/**
* Test class for PhpOffice\PhpWord\Shared\ZipArchive
*
* @runTestsInSeparateProcesses
*/
class ZipArchiveTest extends \PHPUnit_Framework_TestCase
{
/**
* Test add from file and string
*/
public function testAdd()
{
$existingFile = __DIR__ . "/../_files/documents/sheet.xls";
$zipFile = __DIR__ . "/../_files/documents/ziptest.zip";
$object = new ZipArchive();
$object->open($zipFile);
$object->addFile($existingFile, 'xls/new.xls');
$object->addFromString('content/string.txt', 'Test');
$this->assertTrue($object->locateName('xls/new.xls'));
$this->assertEquals('Test', $object->getFromName('content/string.txt'));
unlink($zipFile);
}
}