Remove unused ZipStreamWrapper.php and cleanup some scripts
This commit is contained in:
parent
7c549f5802
commit
1751ab09ee
|
|
@ -42,7 +42,7 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
|
|||
- Writer: Refactor writer classes and make a new Writer abstract class - @ivanlanin GH-160
|
||||
- Reader: Rename AbstractReader > Reader - @ivanlanin
|
||||
- General: Refactor folders: Element, Container, and Exception - @ivanlanin GH-187
|
||||
- General: Remove legacy HashTable and all related properties/methods - @ivanlanin GH-187
|
||||
- General: Remove legacy HashTable and ZipStreamWrapper and all related properties/methods - @ivanlanin GH-187
|
||||
- Container: Create new Container abstract class - @ivanlanin GH-187
|
||||
- Element: Create new Element abstract class - @ivanlanin GH-187
|
||||
|
||||
|
|
|
|||
|
|
@ -312,7 +312,9 @@ abstract class Container extends Element
|
|||
$rID = Media::addMediaElement('footnote', 'image', $src, $image);
|
||||
break;
|
||||
}
|
||||
$image->setRelationId($rID);
|
||||
if (is_int($rID)) {
|
||||
$image->setRelationId($rID);
|
||||
}
|
||||
$this->elements[] = $image;
|
||||
return $image;
|
||||
} else {
|
||||
|
|
@ -366,7 +368,9 @@ abstract class Container extends Element
|
|||
$objectId = $data[1];
|
||||
$object->setRelationId($rID);
|
||||
$object->setObjectId($objectId);
|
||||
$object->setImageRelationId($rIDimg);
|
||||
if (is_int($rIDimg)) {
|
||||
$object->setImageRelationId($rIDimg);
|
||||
}
|
||||
$this->elements[] = $object;
|
||||
return $object;
|
||||
} else {
|
||||
|
|
@ -460,6 +464,7 @@ abstract class Container extends Element
|
|||
* @param string $src
|
||||
* @param mixed $style
|
||||
* @deprecated 0.9.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function addMemoryImage($src, $style = null)
|
||||
{
|
||||
|
|
@ -471,6 +476,7 @@ abstract class Container extends Element
|
|||
*
|
||||
* @param mixed $paragraphStyle
|
||||
* @deprecated 0.9.2
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function createTextRun($paragraphStyle = null)
|
||||
{
|
||||
|
|
@ -482,6 +488,7 @@ abstract class Container extends Element
|
|||
*
|
||||
* @param mixed $paragraphStyle
|
||||
* @deprecated 0.9.2
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function createFootnote($paragraphStyle = null)
|
||||
{
|
||||
|
|
@ -496,11 +503,12 @@ abstract class Container extends Element
|
|||
*/
|
||||
private function checkValidity($method)
|
||||
{
|
||||
// Empty array means the element can be accepted by all containers
|
||||
$validContainers = array(
|
||||
'text' => 'all',
|
||||
'link' => 'all',
|
||||
'textbreak' => 'all',
|
||||
'image' => 'all',
|
||||
'text' => array(),
|
||||
'link' => array(),
|
||||
'textbreak' => array(),
|
||||
'image' => array(),
|
||||
'textrun' => array('section', 'header', 'footer', 'cell'),
|
||||
'listitem' => array('section', 'header', 'footer', 'cell'),
|
||||
'checkbox' => array('section', 'header', 'footer', 'cell'),
|
||||
|
|
@ -511,6 +519,8 @@ abstract class Container extends Element
|
|||
'relationid' => array('header', 'footer', 'footnote'),
|
||||
'title' => array('section'),
|
||||
);
|
||||
// Special condition, e.g. preservetext can only exists in cell when
|
||||
// the cell is located in header or footer
|
||||
$validContainerInContainers = array(
|
||||
'preservetext' => array(array('cell'), array('header', 'footer')),
|
||||
'object' => array(array('cell', 'textrun'), array('section')),
|
||||
|
|
@ -519,7 +529,7 @@ abstract class Container extends Element
|
|||
|
||||
// Check if a method is valid for current container
|
||||
if (array_key_exists($method, $validContainers)) {
|
||||
if (is_array($validContainers[$method])) {
|
||||
if (!empty($validContainers[$method])) {
|
||||
if (!in_array($this->container, $validContainers[$method])) {
|
||||
throw new \BadMethodCallException();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -169,6 +169,7 @@ class Section extends Container
|
|||
* Create header
|
||||
*
|
||||
* @deprecated 0.9.2
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function createHeader()
|
||||
{
|
||||
|
|
@ -179,6 +180,7 @@ class Section extends Container
|
|||
* Create footer
|
||||
*
|
||||
* @deprecated 0.9.2
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function createFooter()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ class Footnote extends Container
|
|||
*
|
||||
* @return int
|
||||
* @deprecated 0.9.2
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function getReferenceId()
|
||||
{
|
||||
|
|
@ -61,6 +62,7 @@ class Footnote extends Container
|
|||
*
|
||||
* @param int $refId
|
||||
* @deprecated 0.9.2
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function setReferenceId($refId)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class Table extends Element
|
|||
/**
|
||||
* Table holder count
|
||||
*
|
||||
* @var array
|
||||
* @var int
|
||||
*/
|
||||
private $docPartId;
|
||||
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ class Footnote
|
|||
* @param string $linkSrc
|
||||
* @return int Reference ID
|
||||
* @deprecated 0.9.2
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function addFootnoteLinkElement($linkSrc)
|
||||
{
|
||||
|
|
@ -76,6 +77,7 @@ class Footnote
|
|||
*
|
||||
* @return array
|
||||
* @deprecated 0.9.2
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function getFootnoteLinkElements()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -22,9 +22,9 @@ abstract class IOFactory
|
|||
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
||||
* @param string $name
|
||||
* @return \PhpOffice\PhpWord\Writer\IWriter
|
||||
* @throws \PhpOffice\PhpWord\Exception\Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function createWriter(PhpWord $phpWord, $name)
|
||||
public static function createWriter(PhpWord $phpWord, $name = 'Word2007')
|
||||
{
|
||||
if ($name !== 'IWriter' && $name !== 'ODText' && $name !== 'RTF' && $name !== 'Word2007') {
|
||||
throw new Exception("\"{$name}\" is not a valid writer.");
|
||||
|
|
@ -39,9 +39,9 @@ abstract class IOFactory
|
|||
*
|
||||
* @param string $name
|
||||
* @return \PhpOffice\PhpWord\Reader\IReader
|
||||
* @throws \PhpOffice\PhpWord\Exception\Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function createReader($name)
|
||||
public static function createReader($name = 'Word2007')
|
||||
{
|
||||
if ($name !== 'IReader' && $name !== 'Word2007') {
|
||||
throw new Exception("\"{$name}\" is not a valid reader.");
|
||||
|
|
|
|||
|
|
@ -194,6 +194,7 @@ class Media
|
|||
/**
|
||||
* Get Header Media Elements
|
||||
*
|
||||
* @param string $prefix header|footer
|
||||
* @return array
|
||||
*/
|
||||
public static function getHeaderMediaElements($prefix = 'header')
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ class PhpWord
|
|||
/**
|
||||
* Create new section
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\Container\Settings $settings
|
||||
* @param array $settings
|
||||
* @return Section
|
||||
*/
|
||||
public function addSection($settings = null)
|
||||
|
|
@ -243,9 +243,10 @@ class PhpWord
|
|||
/**
|
||||
* Create new section
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\Container\Settings $settings
|
||||
* @param array $settings
|
||||
* @return Section
|
||||
* @deprecated 0.9.2
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function createSection($settings = null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -234,7 +234,7 @@ class Word2007 extends Reader implements IReader
|
|||
$styleName = (string)$elm->name['val'];
|
||||
if ($hasParagraphStyle) {
|
||||
$pStyle = $this->loadParagraphStyle($elm);
|
||||
if (!$hasFontStyle) {
|
||||
if (is_array($pStyle) && !$hasFontStyle) {
|
||||
$word->addParagraphStyle($styleName, $pStyle);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,14 +36,14 @@ class ZipArchive
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_tempDir;
|
||||
private $tempDir;
|
||||
|
||||
/**
|
||||
* Zip Archive Stream Handle
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_zip;
|
||||
private $zip;
|
||||
|
||||
/**
|
||||
* Open a new zip archive
|
||||
|
|
@ -53,8 +53,8 @@ class ZipArchive
|
|||
*/
|
||||
public function open($fileName)
|
||||
{
|
||||
$this->_tempDir = sys_get_temp_dir();
|
||||
$this->_zip = new \PclZip($fileName);
|
||||
$this->tempDir = sys_get_temp_dir();
|
||||
$this->zip = new \PclZip($fileName);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -83,13 +83,13 @@ class ZipArchive
|
|||
// 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'];
|
||||
$temppath = $this->tempDir . '/' . $localnameParts['basename'];
|
||||
copy($filename, $temppath);
|
||||
$filename = $temppath;
|
||||
$filenameParts = pathinfo($temppath);
|
||||
}
|
||||
|
||||
$res = $this->_zip->add(
|
||||
$res = $this->zip->add(
|
||||
$filename,
|
||||
PCLZIP_OPT_REMOVE_PATH,
|
||||
$filenameParts['dirname'],
|
||||
|
|
@ -98,8 +98,7 @@ class ZipArchive
|
|||
);
|
||||
|
||||
if ($res == 0) {
|
||||
throw new Exception("Error zipping files : " . $this->_zip->errorInfo(true));
|
||||
return false;
|
||||
throw new Exception("Error zipping files : " . $this->zip->errorInfo(true));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
@ -116,25 +115,24 @@ class ZipArchive
|
|||
$filenameParts = pathinfo($localname);
|
||||
|
||||
// Write $contents to a temp file
|
||||
$handle = fopen($this->_tempDir . '/' . $filenameParts["basename"], "wb");
|
||||
$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"],
|
||||
$res = $this->zip->add(
|
||||
$this->tempDir . '/' . $filenameParts["basename"],
|
||||
PCLZIP_OPT_REMOVE_PATH,
|
||||
$this->_tempDir,
|
||||
$this->tempDir,
|
||||
PCLZIP_OPT_ADD_PATH,
|
||||
$filenameParts["dirname"]
|
||||
);
|
||||
if ($res == 0) {
|
||||
throw new Exception("Error zipping files : " . $this->_zip->errorInfo(true));
|
||||
return false;
|
||||
throw new Exception("Error zipping files : " . $this->zip->errorInfo(true));
|
||||
}
|
||||
|
||||
// Remove temp file
|
||||
unlink($this->_tempDir . '/' . $filenameParts["basename"]);
|
||||
unlink($this->tempDir . '/' . $filenameParts["basename"]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -147,18 +145,18 @@ class ZipArchive
|
|||
*/
|
||||
public function locateName($fileName)
|
||||
{
|
||||
$list = $this->_zip->listContent();
|
||||
$list = $this->zip->listContent();
|
||||
$listCount = count($list);
|
||||
$list_index = -1;
|
||||
$listIndex = -1;
|
||||
for ($i = 0; $i < $listCount; ++$i) {
|
||||
if (strtolower($list[$i]["filename"]) == strtolower($fileName) ||
|
||||
strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) {
|
||||
$list_index = $i;
|
||||
$listIndex = $i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ($list_index > -1);
|
||||
return ($listIndex > -1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -169,31 +167,30 @@ class ZipArchive
|
|||
*/
|
||||
public function getFromName($fileName)
|
||||
{
|
||||
$list = $this->_zip->listContent();
|
||||
$list = $this->zip->listContent();
|
||||
$listCount = count($list);
|
||||
$list_index = -1;
|
||||
$listIndex = -1;
|
||||
for ($i = 0; $i < $listCount; ++$i) {
|
||||
if (strtolower($list[$i]["filename"]) == strtolower($fileName) ||
|
||||
strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) {
|
||||
$list_index = $i;
|
||||
$listIndex = $i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$extracted = "";
|
||||
if ($list_index != -1) {
|
||||
$extracted = $this->_zip->extractByIndex($list_index, PCLZIP_OPT_EXTRACT_AS_STRING);
|
||||
if ($listIndex != -1) {
|
||||
$extracted = $this->zip->extractByIndex($listIndex, PCLZIP_OPT_EXTRACT_AS_STRING);
|
||||
} else {
|
||||
$filename = substr($fileName, 1);
|
||||
$list_index = -1;
|
||||
$fileName = substr($fileName, 1);
|
||||
$listIndex = -1;
|
||||
for ($i = 0; $i < $listCount; ++$i) {
|
||||
if (strtolower($list[$i]["filename"]) == strtolower($fileName) ||
|
||||
strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) {
|
||||
$list_index = $i;
|
||||
$listIndex = $i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$extracted = $this->_zip->extractByIndex($list_index, PCLZIP_OPT_EXTRACT_AS_STRING);
|
||||
$extracted = $this->zip->extractByIndex($listIndex, PCLZIP_OPT_EXTRACT_AS_STRING);
|
||||
}
|
||||
if ((is_array($extracted)) && ($extracted != 0)) {
|
||||
$contents = $extracted[0]["content"];
|
||||
|
|
|
|||
|
|
@ -1,181 +0,0 @@
|
|||
<?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\Exception\Exception;
|
||||
use PhpOffice\PhpWord\Settings;
|
||||
|
||||
/**
|
||||
* Zip stream wrapper
|
||||
*
|
||||
* @codeCoverageIgnore Legacy from PHPExcel
|
||||
*/
|
||||
class ZipStreamWrapper
|
||||
{
|
||||
/**
|
||||
* Internal ZipAcrhive
|
||||
*
|
||||
* @var \ZipAcrhive
|
||||
*/
|
||||
private $_archive;
|
||||
|
||||
/**
|
||||
* Filename in ZipAcrhive
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_fileNameInArchive = '';
|
||||
|
||||
/**
|
||||
* Position in file
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_position = 0;
|
||||
|
||||
/**
|
||||
* Data
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
private $_data = '';
|
||||
|
||||
/**
|
||||
* Register wrapper
|
||||
*/
|
||||
public static function register()
|
||||
{
|
||||
@stream_wrapper_unregister("zip");
|
||||
@stream_wrapper_register("zip", __CLASS__);
|
||||
}
|
||||
|
||||
/**
|
||||
* Open stream
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $mode
|
||||
* @param string $options
|
||||
* @param string $opened_path
|
||||
*/
|
||||
public function streamOpen($path, $mode, $options, &$opened_path)
|
||||
{
|
||||
// Check for mode
|
||||
if ($mode{0} != 'r') {
|
||||
throw new Exception('Mode ' . $mode . ' is not supported. Only read mode is supported.');
|
||||
}
|
||||
|
||||
// Parse URL
|
||||
$url = @parse_url($path);
|
||||
|
||||
// Fix URL
|
||||
if (!is_array($url)) {
|
||||
$url['host'] = substr($path, strlen('zip://'));
|
||||
$url['path'] = '';
|
||||
}
|
||||
if (strpos($url['host'], '#') !== false) {
|
||||
if (!isset($url['fragment'])) {
|
||||
$url['fragment'] = substr($url['host'], strpos($url['host'], '#') + 1) . $url['path'];
|
||||
$url['host'] = substr($url['host'], 0, strpos($url['host'], '#'));
|
||||
unset($url['path']);
|
||||
}
|
||||
} else {
|
||||
$url['host'] = $url['host'] . $url['path'];
|
||||
unset($url['path']);
|
||||
}
|
||||
|
||||
// Open archive
|
||||
$zipClass = Settings::getZipClass();
|
||||
$this->_archive = new $zipClass();
|
||||
$this->_archive->open($url['host']);
|
||||
|
||||
$this->_fileNameInArchive = $url['fragment'];
|
||||
$this->_position = 0;
|
||||
$this->_data = $this->_archive->getFromName($this->_fileNameInArchive);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stat stream
|
||||
*/
|
||||
public function streamStat()
|
||||
{
|
||||
return $this->_archive->statName($this->_fileNameInArchive);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read stream
|
||||
*
|
||||
* @param int $count
|
||||
*/
|
||||
public function streamRead($count)
|
||||
{
|
||||
$ret = substr($this->_data, $this->_position, $count);
|
||||
$this->_position += strlen($ret);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell stream
|
||||
*/
|
||||
public function streamTell()
|
||||
{
|
||||
return $this->_position;
|
||||
}
|
||||
|
||||
/**
|
||||
* EOF stream
|
||||
*/
|
||||
public function streamEof()
|
||||
{
|
||||
return $this->_position >= strlen($this->_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Seek stream
|
||||
*
|
||||
* @param int $offset
|
||||
* @param mixed $whence
|
||||
*/
|
||||
public function streamSeek($offset, $whence)
|
||||
{
|
||||
switch ($whence) {
|
||||
case \SEEK_SET:
|
||||
if ($offset < strlen($this->_data) && $offset >= 0) {
|
||||
$this->_position = $offset;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case \SEEK_CUR:
|
||||
if ($offset >= 0) {
|
||||
$this->_position += $offset;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case \SEEK_END:
|
||||
if (strlen($this->_data) + $offset >= 0) {
|
||||
$this->_position = strlen($this->_data) + $offset;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -23,9 +23,9 @@ use PhpOffice\PhpWord\Writer\ODText\Styles;
|
|||
*/
|
||||
class ODText extends Writer implements IWriter
|
||||
{
|
||||
|
||||
/**
|
||||
* Create new ODText writer
|
||||
*
|
||||
* @param PhpWord $phpWord
|
||||
*/
|
||||
public function __construct(PhpWord $phpWord = null)
|
||||
|
|
|
|||
|
|
@ -82,18 +82,18 @@ class Content extends WriterPart
|
|||
$xmlWriter->writeAttribute('office:version', '1.2');
|
||||
|
||||
// We firstly search all fonts used
|
||||
$_sections = $phpWord->getSections();
|
||||
$countSections = count($_sections);
|
||||
$sections = $phpWord->getSections();
|
||||
$countSections = count($sections);
|
||||
if ($countSections > 0) {
|
||||
$pSection = 0;
|
||||
$numPStyles = 0;
|
||||
$numFStyles = 0;
|
||||
|
||||
foreach ($_sections as $section) {
|
||||
foreach ($sections as $section) {
|
||||
$pSection++;
|
||||
$_elements = $section->getElements();
|
||||
$elements = $section->getElements();
|
||||
|
||||
foreach ($_elements as $element) {
|
||||
foreach ($elements as $element) {
|
||||
if ($element instanceof Text) {
|
||||
$fStyle = $element->getFontStyle();
|
||||
$pStyle = $element->getParagraphStyle();
|
||||
|
|
@ -232,17 +232,13 @@ class Content extends WriterPart
|
|||
$xmlWriter->endElement();
|
||||
$xmlWriter->endElement();
|
||||
|
||||
$_sections = $phpWord->getSections();
|
||||
$countSections = count($_sections);
|
||||
$pSection = 0;
|
||||
|
||||
$sections = $phpWord->getSections();
|
||||
$countSections = count($sections);
|
||||
if ($countSections > 0) {
|
||||
foreach ($_sections as $section) {
|
||||
$pSection++;
|
||||
foreach ($sections as $section) {
|
||||
$elements = $section->getElements();
|
||||
|
||||
$_elements = $section->getElements();
|
||||
|
||||
foreach ($_elements as $element) {
|
||||
foreach ($elements as $element) {
|
||||
if ($element instanceof Text) {
|
||||
$this->writeText($xmlWriter, $element);
|
||||
} elseif ($element instanceof TextRun) {
|
||||
|
|
@ -269,12 +265,6 @@ class Content extends WriterPart
|
|||
$this->writeUnsupportedElement($xmlWriter, 'Element');
|
||||
}
|
||||
}
|
||||
|
||||
if ($pSection == $countSections) {
|
||||
$this->writeEndSection($xmlWriter, $section);
|
||||
} else {
|
||||
$this->writeSection($xmlWriter, $section);
|
||||
}
|
||||
}
|
||||
}
|
||||
$xmlWriter->endElement();
|
||||
|
|
@ -311,19 +301,21 @@ class Content extends WriterPart
|
|||
if (empty($styleFont)) {
|
||||
if (empty($styleParagraph)) {
|
||||
$xmlWriter->writeAttribute('text:style-name', 'P1');
|
||||
} else {
|
||||
$xmlWriter->writeAttribute('text:style-name', $text->getParagraphStyle());
|
||||
} elseif (is_string($styleParagraph)) {
|
||||
$xmlWriter->writeAttribute('text:style-name', $styleParagraph);
|
||||
}
|
||||
$xmlWriter->writeRaw($text->getText());
|
||||
} else {
|
||||
if (empty($styleParagraph)) {
|
||||
$xmlWriter->writeAttribute('text:style-name', 'Standard');
|
||||
} else {
|
||||
$xmlWriter->writeAttribute('text:style-name', $text->getParagraphStyle());
|
||||
} elseif (is_string($styleParagraph)) {
|
||||
$xmlWriter->writeAttribute('text:style-name', $styleParagraph);
|
||||
}
|
||||
// text:span
|
||||
$xmlWriter->startElement('text:span');
|
||||
$xmlWriter->writeAttribute('text:style-name', $styleFont);
|
||||
if (is_string($styleFont)) {
|
||||
$xmlWriter->writeAttribute('text:style-name', $styleFont);
|
||||
}
|
||||
$xmlWriter->writeRaw($text->getText());
|
||||
$xmlWriter->endElement();
|
||||
}
|
||||
|
|
@ -359,35 +351,13 @@ class Content extends WriterPart
|
|||
*
|
||||
* @param XMLWriter $xmlWriter
|
||||
*/
|
||||
protected function writeTextBreak(XMLWriter $xmlWriter = null)
|
||||
protected function writeTextBreak(XMLWriter $xmlWriter)
|
||||
{
|
||||
$xmlWriter->startElement('text:p');
|
||||
$xmlWriter->writeAttribute('text:style-name', 'Standard');
|
||||
$xmlWriter->endElement();
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
/**
|
||||
* Write end section
|
||||
*
|
||||
* @param XMLWriter $xmlWriter
|
||||
* @param Section $section
|
||||
*/
|
||||
private function writeEndSection(XMLWriter $xmlWriter = null, Section $section = null)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Write section
|
||||
*
|
||||
* @param XMLWriter $xmlWriter
|
||||
* @param Section $section
|
||||
*/
|
||||
private function writeSection(XMLWriter $xmlWriter = null, Section $section = null)
|
||||
{
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
/**
|
||||
* Write unsupported element
|
||||
*
|
||||
|
|
|
|||
|
|
@ -170,16 +170,16 @@ class RTF extends Writer implements IWriter
|
|||
}
|
||||
|
||||
// Search all fonts used
|
||||
$_sections = $phpWord->getSections();
|
||||
$countSections = count($_sections);
|
||||
$sections = $phpWord->getSections();
|
||||
$countSections = count($sections);
|
||||
if ($countSections > 0) {
|
||||
$pSection = 0;
|
||||
|
||||
foreach ($_sections as $section) {
|
||||
foreach ($sections as $section) {
|
||||
$pSection++;
|
||||
$_elements = $section->getElements();
|
||||
$elements = $section->getElements();
|
||||
|
||||
foreach ($_elements as $element) {
|
||||
foreach ($elements as $element) {
|
||||
if ($element instanceof Text) {
|
||||
$fStyle = $element->getFontStyle();
|
||||
|
||||
|
|
@ -227,16 +227,16 @@ class RTF extends Writer implements IWriter
|
|||
}
|
||||
|
||||
// Search all fonts used
|
||||
$_sections = $phpWord->getSections();
|
||||
$countSections = count($_sections);
|
||||
$sections = $phpWord->getSections();
|
||||
$countSections = count($sections);
|
||||
if ($countSections > 0) {
|
||||
$pSection = 0;
|
||||
|
||||
foreach ($_sections as $section) {
|
||||
foreach ($sections as $section) {
|
||||
$pSection++;
|
||||
$_elements = $section->getElements();
|
||||
$elements = $section->getElements();
|
||||
|
||||
foreach ($_elements as $element) {
|
||||
foreach ($elements as $element) {
|
||||
if ($element instanceof Text) {
|
||||
$fStyle = $element->getFontStyle();
|
||||
|
||||
|
|
@ -266,15 +266,15 @@ class RTF extends Writer implements IWriter
|
|||
$phpWord = $this->phpWord;
|
||||
$sRTFBody = '';
|
||||
|
||||
$_sections = $phpWord->getSections();
|
||||
$countSections = count($_sections);
|
||||
$sections = $phpWord->getSections();
|
||||
$countSections = count($sections);
|
||||
$pSection = 0;
|
||||
|
||||
if ($countSections > 0) {
|
||||
foreach ($_sections as $section) {
|
||||
foreach ($sections as $section) {
|
||||
$pSection++;
|
||||
$_elements = $section->getElements();
|
||||
foreach ($_elements as $element) {
|
||||
$elements = $section->getElements();
|
||||
foreach ($elements as $element) {
|
||||
if ($element instanceof Text) {
|
||||
$sRTFBody .= $this->getDataContentText($element);
|
||||
} elseif ($element instanceof TextBreak) {
|
||||
|
|
@ -317,14 +317,12 @@ class RTF extends Writer implements IWriter
|
|||
$sRTFText = '';
|
||||
|
||||
$styleFont = $text->getFontStyle();
|
||||
$SfIsObject = ($styleFont instanceof Font) ? true : false;
|
||||
if (!$SfIsObject) {
|
||||
if (is_string($styleFont)) {
|
||||
$styleFont = Style::getStyle($styleFont);
|
||||
}
|
||||
|
||||
$styleParagraph = $text->getParagraphStyle();
|
||||
$SpIsObject = ($styleParagraph instanceof Paragraph) ? true : false;
|
||||
if (!$SpIsObject) {
|
||||
if (is_string($styleParagraph)) {
|
||||
$styleParagraph = Style::getStyle($styleParagraph);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -104,8 +104,8 @@ class Word2007 extends Writer implements IWriter
|
|||
|
||||
// Add section elements
|
||||
$sectionElements = array();
|
||||
$_secElements = Media::getSectionMediaElements();
|
||||
foreach ($_secElements as $element) { // loop through section media elements
|
||||
$secElements = Media::getSectionMediaElements();
|
||||
foreach ($secElements as $element) { // loop through section media elements
|
||||
if ($element['type'] != 'hyperlink') {
|
||||
$this->addFileToPackage($objZip, $element);
|
||||
}
|
||||
|
|
@ -145,33 +145,33 @@ class Word2007 extends Writer implements IWriter
|
|||
}
|
||||
|
||||
// Process header/footer xml files
|
||||
$_cHdrs = 0;
|
||||
$_cFtrs = 0;
|
||||
$cHdrs = 0;
|
||||
$cFtrs = 0;
|
||||
$rID = Media::countSectionMediaElements() + 6;
|
||||
$_sections = $this->phpWord->getSections();
|
||||
$sections = $this->phpWord->getSections();
|
||||
$footers = array();
|
||||
foreach ($_sections as $section) {
|
||||
$_headers = $section->getHeaders();
|
||||
foreach ($_headers as $index => &$_header) {
|
||||
$_cHdrs++;
|
||||
$_header->setRelationId(++$rID);
|
||||
$hdrFile = "header{$_cHdrs}.xml";
|
||||
foreach ($sections as $section) {
|
||||
$headers = $section->getHeaders();
|
||||
foreach ($headers as $index => &$header) {
|
||||
$cHdrs++;
|
||||
$header->setRelationId(++$rID);
|
||||
$hdrFile = "header{$cHdrs}.xml";
|
||||
$sectionElements[] = array('target' => $hdrFile, 'type' => 'header', 'rID' => $rID);
|
||||
$objZip->addFromString(
|
||||
"word/{$hdrFile}",
|
||||
$this->getWriterPart('header')->writeHeader($_header)
|
||||
$this->getWriterPart('header')->writeHeader($header)
|
||||
);
|
||||
}
|
||||
$_footer = $section->getFooter();
|
||||
$footers[++$_cFtrs] = $_footer;
|
||||
if (!is_null($_footer)) {
|
||||
$_footer->setRelationId(++$rID);
|
||||
$_footerCount = $_footer->getSectionId();
|
||||
$ftrFile = "footer{$_footerCount}.xml";
|
||||
$footer = $section->getFooter();
|
||||
$footers[++$cFtrs] = $footer;
|
||||
if (!is_null($footer)) {
|
||||
$footer->setRelationId(++$rID);
|
||||
$footerCount = $footer->getSectionId();
|
||||
$ftrFile = "footer{$footerCount}.xml";
|
||||
$sectionElements[] = array('target' => $ftrFile, 'type' => 'footer', 'rID' => $rID);
|
||||
$objZip->addFromString(
|
||||
"word/{$ftrFile}",
|
||||
$this->getWriterPart('footer')->writeFooter($_footer)
|
||||
$this->getWriterPart('footer')->writeFooter($footer)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -210,7 +210,7 @@ class Word2007 extends Writer implements IWriter
|
|||
$this->getWriterPart('contenttypes')->writeContentTypes(
|
||||
$this->imageTypes,
|
||||
$this->objectTypes,
|
||||
$_cHdrs,
|
||||
$cHdrs,
|
||||
$footers
|
||||
)
|
||||
);
|
||||
|
|
|
|||
|
|
@ -238,6 +238,7 @@ class Base extends WriterPart
|
|||
*
|
||||
* @param XMLWriter $xmlWriter
|
||||
* @param TextBreak $element
|
||||
* @param boolean $withoutP
|
||||
*/
|
||||
protected function writeTextBreak(XMLWriter $xmlWriter, TextBreak $element = null, $withoutP = false)
|
||||
{
|
||||
|
|
@ -1073,7 +1074,7 @@ class Base extends WriterPart
|
|||
* Write media rels (image, embeddings, hyperlink)
|
||||
*
|
||||
* @param XMLWriter $xmlWriter
|
||||
* @param array mediaRels
|
||||
* @param array $mediaRels
|
||||
*/
|
||||
protected function writeMediaRels(XMLWriter $xmlWriter, $mediaRels)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -21,10 +21,10 @@ class ContentTypes extends WriterPart
|
|||
* Write [Content_Types].xml
|
||||
* @param array $imageTypes
|
||||
* @param array $objectTypes
|
||||
* @param int $_cHdrs
|
||||
* @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();
|
||||
|
|
@ -133,7 +133,7 @@ class ContentTypes extends WriterPart
|
|||
'application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml'
|
||||
);
|
||||
|
||||
for ($i = 1; $i <= $_cHdrs; $i++) {
|
||||
for ($i = 1; $i <= $cHdrs; $i++) {
|
||||
$this->writeOverrideContentType(
|
||||
$xmlWriter,
|
||||
'/word/header' . $i . '.xml',
|
||||
|
|
@ -165,7 +165,7 @@ class ContentTypes extends WriterPart
|
|||
* @param string $pContentType Content type
|
||||
* @throws Exception
|
||||
*/
|
||||
private function writeDefaultContentType(XMLWriter $xmlWriter = null, $pPartname = '', $pContentType = '')
|
||||
private function writeDefaultContentType(XMLWriter $xmlWriter, $pPartname = '', $pContentType = '')
|
||||
{
|
||||
if ($pPartname != '' && $pContentType != '') {
|
||||
// Write content type
|
||||
|
|
@ -186,7 +186,7 @@ class ContentTypes extends WriterPart
|
|||
* @param string $pContentType Content type
|
||||
* @throws Exception
|
||||
*/
|
||||
private function writeOverrideContentType(XMLWriter $xmlWriter = null, $pPartname = '', $pContentType = '')
|
||||
private function writeOverrideContentType(XMLWriter $xmlWriter, $pPartname = '', $pContentType = '')
|
||||
{
|
||||
if ($pPartname != '' && $pContentType != '') {
|
||||
// Write content type
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ class DocProps extends WriterPart
|
|||
*
|
||||
* @param PhpWord $phpWord
|
||||
*/
|
||||
public function writeDocPropsCore(PhpWord $phpWord = null)
|
||||
public function writeDocPropsCore(PhpWord $phpWord)
|
||||
{
|
||||
// Create XML writer
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ class Document extends Base
|
|||
{
|
||||
$xmlWriter->startElement('w:p');
|
||||
$xmlWriter->startElement('w:pPr');
|
||||
$this->writeEndSection($xmlWriter, $section, 3);
|
||||
$this->writeEndSection($xmlWriter, $section);
|
||||
$xmlWriter->endElement();
|
||||
$xmlWriter->endElement();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,11 +98,10 @@ class FooterTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$src = __DIR__ . "/../_files/images/earth.jpg";
|
||||
$oFooter = new Footer(1);
|
||||
$element1 = $oFooter->addImage($src);
|
||||
$element2 = $oFooter->addMemoryImage($src); // @deprecated
|
||||
$element = $oFooter->addImage($src);
|
||||
|
||||
$this->assertCount(2, $oFooter->getElements());
|
||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element1);
|
||||
$this->assertCount(1, $oFooter->getElements());
|
||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -107,11 +107,10 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$src = __DIR__ . "/../_files/images/earth.jpg";
|
||||
$oHeader = new Header(1);
|
||||
$element1 = $oHeader->addImage($src);
|
||||
$element2 = $oHeader->addMemoryImage($src); // @deprecated
|
||||
$element = $oHeader->addImage($src);
|
||||
|
||||
$this->assertCount(2, $oHeader->getElements());
|
||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element1);
|
||||
$this->assertCount(1, $oHeader->getElements());
|
||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -84,7 +84,6 @@ class SectionTest extends \PHPUnit_Framework_TestCase
|
|||
$section->addListItem(utf8_decode('ä'));
|
||||
$section->addObject($objectSource);
|
||||
$section->addImage($imageSource);
|
||||
$section->addMemoryImage($imageUrl);
|
||||
$section->addTitle(utf8_decode('ä'), 1);
|
||||
$section->addTextRun();
|
||||
$section->addFootnote();
|
||||
|
|
@ -93,7 +92,7 @@ class SectionTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
$elementCollection = $section->getElements();
|
||||
$elementTypes = array('Text', 'Link', 'TextBreak', 'PageBreak',
|
||||
'Table', 'ListItem', 'Object', 'Image', 'Image',
|
||||
'Table', 'ListItem', 'Object', 'Image',
|
||||
'Title', 'TextRun', 'Footnote', 'CheckBox');
|
||||
$i = 0;
|
||||
foreach ($elementTypes as $elementType) {
|
||||
|
|
|
|||
|
|
@ -123,11 +123,10 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$src = __DIR__ . "/../_files/images/earth.jpg";
|
||||
$oCell = new Cell('section', 1);
|
||||
$element1 = $oCell->addImage($src);
|
||||
$element2 = $oCell->addMemoryImage($src); // @deprecated
|
||||
$element = $oCell->addImage($src);
|
||||
|
||||
$this->assertCount(2, $oCell->getElements());
|
||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element1);
|
||||
$this->assertCount(1, $oCell->getElements());
|
||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue