Merge pull request #104 from ivanlanin/develop

Basic version of Reader for Word2007
This commit is contained in:
Progi1984 2014-03-12 10:39:26 +01:00
commit b58d1c8179
105 changed files with 2058 additions and 646 deletions

View File

@ -267,4 +267,4 @@ class PHPWord
trigger_error('Template file ' . $strFilename . ' not found.', E_USER_ERROR); trigger_error('Template file ' . $strFilename . ' not found.', E_USER_ERROR);
} }
} }
} }

View File

@ -82,4 +82,4 @@ class PHPWord_Autoloader
} }
} }
} }
} }

View File

@ -30,6 +30,13 @@
*/ */
class PHPWord_DocumentProperties class PHPWord_DocumentProperties
{ {
/** Constants */
const PROPERTY_TYPE_BOOLEAN = 'b';
const PROPERTY_TYPE_INTEGER = 'i';
const PROPERTY_TYPE_FLOAT = 'f';
const PROPERTY_TYPE_DATE = 'd';
const PROPERTY_TYPE_STRING = 's';
const PROPERTY_TYPE_UNKNOWN = 'u';
/** /**
* Creator * Creator
@ -101,21 +108,36 @@ class PHPWord_DocumentProperties
*/ */
private $_company; private $_company;
/**
* Manager
*
* @var string
*/
private $_manager;
/**
* Custom Properties
*
* @var string
*/
private $_customProperties = array();
/** /**
* Create new PHPWord_DocumentProperties * Create new PHPWord_DocumentProperties
*/ */
public function __construct() public function __construct()
{ {
$this->_creator = ''; $this->_creator = '';
$this->_lastModifiedBy = $this->_creator; $this->_lastModifiedBy = $this->_creator;
$this->_created = time(); $this->_created = time();
$this->_modified = time(); $this->_modified = time();
$this->_title = ''; $this->_title = '';
$this->_subject = ''; $this->_subject = '';
$this->_description = ''; $this->_description = '';
$this->_keywords = ''; $this->_keywords = '';
$this->_category = ''; $this->_category = '';
$this->_company = ''; $this->_company = '';
$this->_manager = '';
} }
/** /**
@ -343,4 +365,243 @@ class PHPWord_DocumentProperties
$this->_company = $pValue; $this->_company = $pValue;
return $this; return $this;
} }
}
/**
* Get Manager
*
* @return string
*/
public function getManager()
{
return $this->_manager;
}
/**
* Set Manager
*
* @param string $pValue
* @return PHPExcel_DocumentProperties
*/
public function setManager($pValue = '')
{
$this->_manager = $pValue;
return $this;
}
/**
* Get a List of Custom Property Names
*
* @return array of string
*/
public function getCustomProperties()
{
return array_keys($this->_customProperties);
}
/**
* Check if a Custom Property is defined
*
* @param string $propertyName
* @return boolean
*/
public function isCustomPropertySet($propertyName)
{
return isset($this->_customProperties[$propertyName]);
}
/**
* Get a Custom Property Value
*
* @param string $propertyName
* @return string
*/
public function getCustomPropertyValue($propertyName)
{
if (isset($this->_customProperties[$propertyName])) {
return $this->_customProperties[$propertyName]['value'];
}
}
/**
* Get a Custom Property Type
*
* @param string $propertyName
* @return string
*/
public function getCustomPropertyType($propertyName)
{
if (isset($this->_customProperties[$propertyName])) {
return $this->_customProperties[$propertyName]['type'];
}
}
/**
* Set a Custom Property
*
* @param string $propertyName
* @param mixed $propertyValue
* @param string $propertyType
* 'i': Integer
* 'f': Floating Point
* 's': String
* 'd': Date/Time
* 'b': Boolean
* @return PHPExcel_DocumentProperties
*/
public function setCustomProperty($propertyName, $propertyValue = '', $propertyType = null)
{
if (($propertyType === null) || (!in_array($propertyType, array(
self::PROPERTY_TYPE_INTEGER,
self::PROPERTY_TYPE_FLOAT,
self::PROPERTY_TYPE_STRING,
self::PROPERTY_TYPE_DATE,
self::PROPERTY_TYPE_BOOLEAN
)))) {
if ($propertyValue === null) {
$propertyType = self::PROPERTY_TYPE_STRING;
} elseif (is_float($propertyValue)) {
$propertyType = self::PROPERTY_TYPE_FLOAT;
} elseif (is_int($propertyValue)) {
$propertyType = self::PROPERTY_TYPE_INTEGER;
} elseif (is_bool($propertyValue)) {
$propertyType = self::PROPERTY_TYPE_BOOLEAN;
} else {
$propertyType = self::PROPERTY_TYPE_STRING;
}
}
$this->_customProperties[$propertyName] = array(
'value' => $propertyValue,
'type' => $propertyType
);
return $this;
}
/**
* Convert document propery based on type
*
* @param mixed $propertyValue
* @param string $propertyType
* @return mixed
*/
public static function convertProperty($propertyValue, $propertyType)
{
switch ($propertyType) {
case 'empty': // Empty
return '';
break;
case 'null': // Null
return null;
break;
case 'i1': // 1-Byte Signed Integer
case 'i2': // 2-Byte Signed Integer
case 'i4': // 4-Byte Signed Integer
case 'i8': // 8-Byte Signed Integer
case 'int': // Integer
return (int) $propertyValue;
break;
case 'ui1': // 1-Byte Unsigned Integer
case 'ui2': // 2-Byte Unsigned Integer
case 'ui4': // 4-Byte Unsigned Integer
case 'ui8': // 8-Byte Unsigned Integer
case 'uint': // Unsigned Integer
return abs((int) $propertyValue);
break;
case 'r4': // 4-Byte Real Number
case 'r8': // 8-Byte Real Number
case 'decimal': // Decimal
return (float) $propertyValue;
break;
case 'lpstr': // LPSTR
case 'lpwstr': // LPWSTR
case 'bstr': // Basic String
return $propertyValue;
break;
case 'date': // Date and Time
case 'filetime': // File Time
return strtotime($propertyValue);
break;
case 'bool': // Boolean
return ($propertyValue == 'true') ? true : false;
break;
case 'cy': // Currency
case 'error': // Error Status Code
case 'vector': // Vector
case 'array': // Array
case 'blob': // Binary Blob
case 'oblob': // Binary Blob Object
case 'stream': // Binary Stream
case 'ostream': // Binary Stream Object
case 'storage': // Binary Storage
case 'ostorage': // Binary Storage Object
case 'vstream': // Binary Versioned Stream
case 'clsid': // Class ID
case 'cf': // Clipboard Data
return $propertyValue;
break;
}
return $propertyValue;
}
/**
* Convert document property type
*
* @param string $propertyType
* @return mixed
*/
public static function convertPropertyType($propertyType)
{
switch ($propertyType) {
case 'i1': // 1-Byte Signed Integer
case 'i2': // 2-Byte Signed Integer
case 'i4': // 4-Byte Signed Integer
case 'i8': // 8-Byte Signed Integer
case 'int': // Integer
case 'ui1': // 1-Byte Unsigned Integer
case 'ui2': // 2-Byte Unsigned Integer
case 'ui4': // 4-Byte Unsigned Integer
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
case 'array': // Array
case 'blob': // Binary Blob
case 'oblob': // Binary Blob Object
case 'stream': // Binary Stream
case 'ostream': // Binary Stream Object
case 'storage': // Binary Storage
case 'ostorage': // Binary Storage Object
case 'vstream': // Binary Versioned Stream
case 'clsid': // Class ID
case 'cf': // Clipboard Data
return self::PROPERTY_TYPE_UNKNOWN;
break;
}
return self::PROPERTY_TYPE_UNKNOWN;
}
}

View File

@ -46,4 +46,4 @@ class PHPWord_Exception extends Exception
$e->file = $file; $e->file = $file;
throw $e; throw $e;
} }
} }

View File

@ -12,4 +12,4 @@ use Exception;
*/ */
class InvalidImageException extends Exception class InvalidImageException extends Exception
{ {
} }

View File

@ -12,4 +12,4 @@ use InvalidArgumentException;
*/ */
class InvalidStyleException extends InvalidArgumentException class InvalidStyleException extends InvalidArgumentException
{ {
} }

View File

@ -12,4 +12,4 @@ use Exception;
*/ */
class UnsupportedImageTypeException extends Exception class UnsupportedImageTypeException extends Exception
{ {
} }

View File

@ -2,7 +2,7 @@
/** /**
* PHPWord * PHPWord
* *
* Copyright (c) 2011 PHPWord * Copyright (c) 2014 PHPWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -20,106 +20,108 @@
* *
* @category PHPWord * @category PHPWord
* @package PHPWord * @package PHPWord
* @copyright Copyright (c) 010 PHPWord * @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version Beta 0.6.3, 08.07.2011 * @version 0.7.0
*/ */
/** /**
* PHPWord_Footnote * PHPWord_Footnote
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_Footnote { class PHPWord_Footnote
{
/** /**
* Footnote Elements * Footnote Elements
* *
* @var array * @var array
*/ */
private static $_footnoteCollection = array(); private static $_footnoteCollection = array();
/** /**
* Footnote Link Elements * Footnote Link Elements
* *
* @var array * @var array
*/ */
private static $_footnoteLink = array(); private static $_footnoteLink = array();
/** /**
* Add new Footnote Element * Add new Footnote Element
* *
* @param string $linkSrc * @param string $linkSrc
* @param string $linkName * @param string $linkName
* *
* @return mixed * @return mixed
*/ */
public static function addFootnoteElement(PHPWord_Section_Footnote $footnote) { public static function addFootnoteElement(PHPWord_Section_Footnote $footnote)
$refID = self::countFootnoteElements() + 2; {
$refID = self::countFootnoteElements() + 2;
self::$_footnoteCollection[] = $footnote; self::$_footnoteCollection[] = $footnote;
return $refID; return $refID;
} }
/** /**
* Get Footnote Elements * Get Footnote Elements
* *
* @return array * @return array
*/ */
public static function getFootnoteElements() { public static function getFootnoteElements()
return self::$_footnoteCollection; {
} return self::$_footnoteCollection;
}
/** /**
* Get Footnote Elements Count * Get Footnote Elements Count
* *
* @return int * @return int
*/ */
public static function countFootnoteElements() { public static function countFootnoteElements()
return count(self::$_footnoteCollection); {
} return count(self::$_footnoteCollection);
}
/** /**
* Add new Footnote Link Element * Add new Footnote Link Element
* *
* @param string $src * @param string $src
* @param string $type * @param string $type
* *
* @return mixed * @return mixed
*/ */
public static function addFootnoteLinkElement($linkSrc) { public static function addFootnoteLinkElement($linkSrc)
$rID = self::countFootnoteLinkElements() + 1; {
$rID = self::countFootnoteLinkElements() + 1;
$link = array(); $link = array();
$link['target'] = $linkSrc; $link['target'] = $linkSrc;
$link['rID'] = $rID; $link['rID'] = $rID;
$link['type'] = 'hyperlink'; $link['type'] = 'hyperlink';
self::$_footnoteLink[] = $link; self::$_footnoteLink[] = $link;
return $rID; return $rID;
} }
/** /**
* Get Footnote Link Elements * Get Footnote Link Elements
* *
* @return array * @return array
*/ */
public static function getFootnoteLinkElements() { public static function getFootnoteLinkElements()
return self::$_footnoteLink; {
} return self::$_footnoteLink;
}
/** /**
* Get Footnote Link Elements Count * Get Footnote Link Elements Count
* *
* @return int * @return int
*/ */
public static function countFootnoteLinkElements() { public static function countFootnoteLinkElements()
return count(self::$_footnoteLink); {
} return count(self::$_footnoteLink);
}
} }

View File

@ -69,7 +69,7 @@ class PHPWord_HashTable
// Check if an array was passed // Check if an array was passed
if ($pSource == null) { if ($pSource == null) {
return; return;
} else if (!is_array($pSource)) { } elseif (!is_array($pSource)) {
throw new Exception('Invalid array parameter passed.'); throw new Exception('Invalid array parameter passed.');
} }
@ -91,7 +91,7 @@ class PHPWord_HashTable
$hashIndex = $pSource->getHashIndex(); $hashIndex = $pSource->getHashIndex();
if (is_null($hashIndex)) { if (is_null($hashIndex)) {
$hashCode = $pSource->getHashCode(); $hashCode = $pSource->getHashCode();
} else if (isset ($this->_keyMap[$hashIndex])) { } elseif (isset ($this->_keyMap[$hashIndex])) {
$hashCode = $this->_keyMap[$hashIndex]; $hashCode = $this->_keyMap[$hashIndex];
} else { } else {
$hashCode = $pSource->getHashCode(); $hashCode = $pSource->getHashCode();

View File

@ -37,7 +37,8 @@ class PHPWord_IOFactory
* @var array * @var array
*/ */
private static $_searchLocations = array( private static $_searchLocations = array(
array('type' => 'IWriter', 'path' => 'PHPWord/Writer/{0}.php', 'class' => 'PHPWord_Writer_{0}') array('type' => 'IWriter', 'path' => 'PHPWord/Writer/{0}.php', 'class' => 'PHPWord_Writer_{0}'),
array('type' => 'IReader', 'path' => 'PHPWord/Reader/{0}.php', 'class' => 'PHPWord_Reader_{0}' ),
); );
/** /**
@ -118,4 +119,40 @@ class PHPWord_IOFactory
throw new Exception("No $searchType found for type $writerType"); throw new Exception("No $searchType found for type $writerType");
} }
/**
* Create PHPWord_Reader_IReader
*
* @param string $readerType Example: Word2007
* @return PHPWord_Reader_IReader
*/
public static function createReader($readerType = '')
{
$searchType = 'IReader';
foreach (self::$_searchLocations as $searchLocation) {
if ($searchLocation['type'] == $searchType) {
$className = str_replace('{0}', $readerType, $searchLocation['class']);
$instance = new $className();
if ($instance !== null) {
return $instance;
}
}
}
throw new PHPWord_Exception("No $searchType found for type $readerType");
}
/**
* Loads PHPWord from file
*
* @param string $pFilename The name of the file
* @return PHPWord
*/
public static function load($pFilename, $readerType = 'Word2007')
{
$reader = self::createReader($readerType);
return $reader->load($pFilename);
}
} }

View File

@ -330,4 +330,3 @@ class PHPWord_Media
return self::$_footerMedia; return self::$_footerMedia;
} }
} }

View File

@ -0,0 +1,105 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.7.0
*/
/**
* PHPWord_Reader_Abstract
*/
abstract class PHPWord_Reader_Abstract implements PHPWord_Reader_IReader
{
/**
* Read data only?
*
* @var boolean
*/
protected $readDataOnly = true;
protected $fileHandle = true;
/**
* Read data only?
*
* @return boolean
*/
public function getReadDataOnly()
{
// return $this->readDataOnly;
return true;
}
/**
* Set read data only
*
* @param boolean $pValue
* @return PHPWord_Reader_IReader
*/
public function setReadDataOnly($pValue = true)
{
$this->readDataOnly = $pValue;
return $this;
}
/**
* Open file for reading
*
* @param string $pFilename
* @throws PHPWord_Exception
* @return resource
*/
protected function openFile($pFilename)
{
// Check if file exists
if (!file_exists($pFilename) || !is_readable($pFilename)) {
throw new PHPWord_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
}
// Open file
$this->fileHandle = fopen($pFilename, 'r');
if ($this->fileHandle === false) {
throw new PHPWord_Exception("Could not open file " . $pFilename . " for reading.");
}
}
/**
* Can the current PHPWord_Reader_IReader read the file?
*
* @param string $pFilename
* @return boolean
* @throws PHPWord_Exception
*/
public function canRead($pFilename)
{
// Check if file exists
try {
$this->openFile($pFilename);
} catch (Exception $e) {
return false;
}
fclose($this->fileHandle);
return $readable;
}
}

View File

@ -0,0 +1,47 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.7.0
*/
/**
* PHPWord_Reader_IReader
*/
interface PHPWord_Reader_IReader
{
/**
* Can the current PHPWord_Reader_IReader read the file?
*
* @param string $pFilename
* @return boolean
*/
public function canRead($pFilename);
/**
* Loads PHPWord from file
*
* @param string $pFilename
*/
public function load($pFilename);
}

View File

@ -0,0 +1,468 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.7.0
*/
/** PHPWord root directory */
if (!defined('PHPWORD_BASE_PATH')) {
define('PHPWORD_BASE_PATH', dirname(__FILE__) . '/../../');
require(PHPWORD_BASE_PATH . 'PHPWord/Autoloader.php');
}
/**
* PHPWord_Reader_Word2007
*/
class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements
PHPWord_Reader_IReader
{
/**
* Create a new PHPWord_Reader_Word2007 instance
*/
public function __construct()
{
}
/**
* Can the current PHPWord_Reader_IReader read the file?
*
* @param string $pFilename
* @return bool
*/
public function canRead($pFilename)
{
// Check if file exists
if (!file_exists($pFilename)) {
throw new PHPWord_Exception(
"Could not open {$pFilename} for reading! File does not exist."
);
}
$return = false;
// Load file
$zip = new ZipArchive;
if ($zip->open($pFilename) === true) {
// check if it is an OOXML archive
$rels = simplexml_load_string($this->getFromZipArchive($zip, "_rels/.rels"));
if ($rels !== false) {
foreach ($rels->Relationship as $rel) {
switch ($rel["Type"]) {
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument":
if (basename($rel["Target"]) == 'document.xml') {
$return = true;
}
break;
}
}
}
$zip->close();
}
return $return;
}
/**
* Get from zip archive
*
* @param ZipArchive $archive
* @param string $fileName
* @param bool $removeNamespace
*/
public function getFromZipArchive(
$archive,
$fileName = '',
$removeNamespace = false
) {
// Root-relative paths
if (strpos($fileName, '//') !== false) {
$fileName = substr($fileName, strpos($fileName, '//') + 1);
}
$fileName = PHPWord_Shared_File::realpath($fileName);
// Apache POI fixes
$contents = $archive->getFromName($fileName);
if ($contents === false) {
$contents = $archive->getFromName(substr($fileName, 1));
}
// Remove namespaces from elements and attributes name
if ($removeNamespace) {
$contents = preg_replace('~(</?|\s)w:~is', '$1', $contents);
}
return $contents;
}
/**
* Loads PHPWord from file
*
* @param string $pFilename
* @return PHPWord|null
*/
public function load($pFilename)
{
// Check if file exists and can be read
if (!$this->canRead($pFilename)) {
return;
}
// Initialisations
$word = new PHPWord;
$zip = new ZipArchive;
$zip->open($pFilename);
// Read properties and documents
$rels = simplexml_load_string($this->getFromZipArchive($zip, "_rels/.rels"));
foreach ($rels->Relationship as $rel) {
switch ($rel["Type"]) {
// Core properties
case "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties":
$xmlCore = simplexml_load_string($this->getFromZipArchive($zip, "{$rel['Target']}"));
if (is_object($xmlCore)) {
$xmlCore->registerXPathNamespace("dc", "http://purl.org/dc/elements/1.1/");
$xmlCore->registerXPathNamespace("dcterms", "http://purl.org/dc/terms/");
$xmlCore->registerXPathNamespace("cp", "http://schemas.openxmlformats.org/package/2006/metadata/core-properties");
$docProps = $word->getProperties();
$docProps->setCreator((string) self::arrayItem($xmlCore->xpath("dc:creator")));
$docProps->setLastModifiedBy((string) self::arrayItem($xmlCore->xpath("cp:lastModifiedBy")));
$docProps->setCreated(strtotime(self::arrayItem($xmlCore->xpath("dcterms:created"))));
$docProps->setModified(strtotime(self::arrayItem($xmlCore->xpath("dcterms:modified"))));
$docProps->setTitle((string) self::arrayItem($xmlCore->xpath("dc:title")));
$docProps->setDescription((string) self::arrayItem($xmlCore->xpath("dc:description")));
$docProps->setSubject((string) self::arrayItem($xmlCore->xpath("dc:subject")));
$docProps->setKeywords((string) self::arrayItem($xmlCore->xpath("cp:keywords")));
$docProps->setCategory((string) self::arrayItem($xmlCore->xpath("cp:category")));
}
break;
// Extended properties
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties":
$xmlCore = simplexml_load_string($this->getFromZipArchive($zip, "{$rel['Target']}"));
if (is_object($xmlCore)) {
$docProps = $word->getProperties();
if (isset($xmlCore->Company)) {
$docProps->setCompany((string) $xmlCore->Company);
}
if (isset($xmlCore->Manager)) {
$docProps->setManager((string) $xmlCore->Manager);
}
}
break;
// Custom properties
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties":
$xmlCore = simplexml_load_string($this->getFromZipArchive($zip, "{$rel['Target']}"));
if (is_object($xmlCore)) {
$docProps = $word->getProperties();
foreach ($xmlCore as $xmlProperty) {
$cellDataOfficeAttributes = $xmlProperty->attributes();
if (isset($cellDataOfficeAttributes['name'])) {
$propertyName = (string) $cellDataOfficeAttributes['name'];
$cellDataOfficeChildren = $xmlProperty->children("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes");
$attributeType = $cellDataOfficeChildren->getName();
$attributeValue = (string) $cellDataOfficeChildren->{$attributeType};
$attributeValue = PHPWord_DocumentProperties::convertProperty($attributeValue, $attributeType);
$attributeType = PHPWord_DocumentProperties::convertPropertyType($attributeType);
$docProps->setCustomProperty($propertyName, $attributeValue, $attributeType);
}
}
}
break;
// Document
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument":
$dir = dirname($rel["Target"]);
$archive = "$dir/_rels/" . basename($rel["Target"]) . ".rels";
$relsDoc = simplexml_load_string($this->getFromZipArchive($zip, $archive));
$relsDoc->registerXPathNamespace("rel", "http://schemas.openxmlformats.org/package/2006/relationships");
$xpath = self::arrayItem(
$relsDoc->xpath("rel:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles']")
);
$xmlDoc = simplexml_load_string($this->getFromZipArchive($zip, "{$rel['Target']}", true));
if (is_object($xmlDoc)) {
$section = $word->createSection();
foreach ($xmlDoc->body->children() as $elm) {
$elmName = $elm->getName();
if ($elmName == 'p') { // Paragraph/section
// Create new section if section setting found
if ($elm->pPr->sectPr) {
$section->setSettings($this->loadSectionSettings($elm->pPr));
$section = $word->createSection();
continue;
}
// Has w:r? It's either text or textrun
if ($elm->r) {
// w:r = 1? It's a plain paragraph
if (count($elm->r) == 1) {
$section->addText(
$elm->r->t,
$this->loadFontStyle($elm->r)
);
// w:r more than 1? It's a textrun
} else {
$textRun = $section->createTextRun();
foreach ($elm->r as $r) {
$textRun->addText(
$r->t,
$this->loadFontStyle($r)
);
}
}
// No, it's a textbreak
} else {
$section->addTextBreak();
}
} elseif ($elmName == 'sectPr') {
// Last section setting
$section->setSettings($this->loadSectionSettings($xmlDoc->body));
}
}
}
break;
}
}
// Read styles
$docRels = simplexml_load_string($this->getFromZipArchive($zip, "word/_rels/document.xml.rels"));
foreach ($docRels->Relationship as $rel) {
switch ($rel["Type"]) {
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles":
$xmlStyle = simplexml_load_string($this->getFromZipArchive($zip, "word/{$rel['Target']}", true));
if (is_object($xmlStyle)) {
foreach ($xmlStyle->children() as $elm) {
if ($elm->getName() != 'style') {
continue;
}
unset($pStyle);
unset($fStyle);
$hasParagraphStyle = isset($elm->pPr);
$hasFontStyle = isset($elm->rPr);
$styleName = (string)$elm->name['val'];
if ($hasParagraphStyle) {
$pStyle = $this->loadParagraphStyle($elm);
if (!$hasFontStyle) {
$word->addParagraphStyle($styleName, $pStyle);
}
}
if ($hasFontStyle) {
$fStyle = $this->loadFontStyle($elm);
$word->addFontStyle($styleName, $fStyle, $pStyle);
}
}
}
break;
}
}
$zip->close();
return $word;
}
/**
* Load section settings from SimpleXMLElement
*
* @param SimpleXMLElement $elm
* @return array|string|null
*
* @todo Implement gutter
*/
private function loadSectionSettings($elm)
{
if ($xml = $elm->sectPr) {
$setting = array();
if ($xml->type) {
$setting['breakType'] = (string)$xml->type['val'];
}
if ($xml->pgSz) {
if (isset($xml->pgSz['w'])) {
$setting['pageSizeW'] = (int)$xml->pgSz['w'];
}
if (isset($xml->pgSz['h'])) {
$setting['pageSizeH'] = (int)$xml->pgSz['h'];
}
if (isset($xml->pgSz['orient'])) {
$setting['orientation'] = (string)$xml->pgSz['orient'];
}
}
if ($xml->pgMar) {
if (isset($xml->pgMar['top'])) {
$setting['topMargin'] = (int)$xml->pgMar['top'];
}
if (isset($xml->pgMar['left'])) {
$setting['leftMargin'] = (int)$xml->pgMar['left'];
}
if (isset($xml->pgMar['bottom'])) {
$setting['bottomMargin'] = (int)$xml->pgMar['bottom'];
}
if (isset($xml->pgMar['right'])) {
$setting['rightMargin'] = (int)$xml->pgMar['right'];
}
if (isset($xml->pgMar['header'])) {
$setting['headerHeight'] = (int)$xml->pgMar['header'];
}
if (isset($xml->pgMar['footer'])) {
$setting['footerHeight'] = (int)$xml->pgMar['footer'];
}
if (isset($xml->pgMar['gutter'])) {
// $setting['gutter'] = (int)$xml->pgMar['gutter'];
}
}
if ($xml->cols) {
if (isset($xml->cols['num'])) {
$setting['colsNum'] = (int)$xml->cols['num'];
}
if (isset($xml->cols['space'])) {
$setting['colsSpace'] = (int)$xml->cols['space'];
}
}
return $setting;
} else {
return null;
}
}
/**
* Load paragraph style from SimpleXMLElement
*
* @param SimpleXMLElement $elm
* @return array|string|null
*/
private function loadParagraphStyle($elm)
{
if ($xml = $elm->pPr) {
if ($xml->pStyle) {
return (string)$xml->pStyle['val'];
}
$style = array();
if ($xml->jc) {
$style['align'] = (string)$xml->jc['val'];
}
if ($xml->ind) {
if (isset($xml->ind->left)) {
$style['indent'] = (int)$xml->ind->left;
}
if (isset($xml->ind->hanging)) {
$style['hanging'] = (int)$xml->ind->hanging;
}
if (isset($xml->ind->line)) {
$style['spacing'] = (int)$xml->ind->line;
}
}
if ($xml->spacing) {
if (isset($xml->spacing['after'])) {
$style['spaceAfter'] = (int)$xml->spacing['after'];
}
if (isset($xml->spacing['before'])) {
$style['spaceBefore'] = (int)$xml->spacing['before'];
}
if (isset($xml->spacing['line'])) {
$style['spacing'] = (int)$xml->spacing['line'];
}
}
if ($xml->basedOn) {
$style['basedOn'] = (string)$xml->basedOn['val'];
}
if ($xml->next) {
$style['next'] = (string)$xml->next['val'];
}
if ($xml->widowControl) {
$style['widowControl'] = false;
}
if ($xml->keepNext) {
$style['keepNext'] = true;
}
if ($xml->keepLines) {
$style['keepLines'] = true;
}
if ($xml->pageBreakBefore) {
$style['pageBreakBefore'] = true;
}
return $style;
} else {
return null;
}
}
/**
* Load font style from SimpleXMLElement
*
* @param SimpleXMLElement $elm
* @return array|string|null
*/
private function loadFontStyle($elm)
{
if ($xml = $elm->rPr) {
if ($xml->rStyle) {
return (string)$xml->rStyle['val'];
}
$style = array();
if ($xml->rFonts) {
$style['name'] = (string)$xml->rFonts['ascii'];
}
if ($xml->sz) {
$style['size'] = (int)$xml->sz['val'] / 2;
}
if ($xml->color) {
$style['color'] = (string)$xml->color['val'];
}
if ($xml->b) {
$style['bold'] = true;
}
if ($xml->i) {
$style['italic'] = true;
}
if ($xml->u) {
$style['underline'] = (string)$xml->u['val'];
}
if ($xml->strike) {
$style['strikethrough'] = true;
}
if ($xml->highlight) {
$style['fgColor'] = (string)$xml->highlight['val'];
}
if ($xml->vertAlign) {
if ($xml->vertAlign['val'] == 'superscript') {
$style['superScript'] = true;
} else {
$style['subScript'] = true;
}
}
return $style;
} else {
return null;
}
}
/**
* Get array item
*
* @param array $array
* @param mixed $key
* @return mixed|null
*/
private static function arrayItem($array, $key = 0)
{
return (isset($array[$key]) ? $array[$key] : null);
}
}

View File

@ -77,7 +77,16 @@ class PHPWord_Section
{ {
$this->_sectionCount = $sectionCount; $this->_sectionCount = $sectionCount;
$this->_settings = new PHPWord_Section_Settings(); $this->_settings = new PHPWord_Section_Settings();
$this->setSettings($settings);
}
/**
* Set Section Settings
*
* @param array $settings
*/
public function setSettings($settings = null)
{
if (!is_null($settings) && is_array($settings)) { if (!is_null($settings) && is_array($settings)) {
foreach ($settings as $key => $value) { foreach ($settings as $key => $value) {
if (substr($key, 0, 1) != '_') { if (substr($key, 0, 1) != '_') {
@ -416,11 +425,12 @@ class PHPWord_Section
* @param string $text * @param string $text
* @return PHPWord_Section_Footnote * @return PHPWord_Section_Footnote
*/ */
public function createFootnote($styleParagraph = null) { public function createFootnote($styleParagraph = null)
$footnote = new PHPWord_Section_Footnote($styleParagraph); {
$refID = PHPWord_Footnote::addFootnoteElement($footnote); $footnote = new PHPWord_Section_Footnote($styleParagraph);
$footnote->setReferenceId($refID); $refID = PHPWord_Footnote::addFootnoteElement($footnote);
$this->_elementCollection[] = $footnote; $footnote->setReferenceId($refID);
return $footnote; $this->_elementCollection[] = $footnote;
return $footnote;
} }
} }

View File

@ -210,4 +210,4 @@ class PHPWord_Section_Footer
{ {
return $this->_footerCount; return $this->_footerCount;
} }
} }

View File

@ -2,7 +2,7 @@
/** /**
* PHPWord * PHPWord
* *
* Copyright (c) 2011 PHPWord * Copyright (c) 2014 PHPWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -11,138 +11,141 @@
* *
* This library is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @category PHPWord
* @package PHPWord * @package PHPWord
* @copyright Copyright (c) 010 PHPWord * @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version Beta 0.6.3, 08.07.2011 * @version 0.7.0
*/ */
/** /**
* PHPWord_Section_Footnote * PHPWord_Section_Footnote
*
* @category PHPWord
* @package PHPWord_Section
* @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_Section_Footnote { class PHPWord_Section_Footnote
{
/** /**
* Paragraph style * Paragraph style
* *
* @var PHPWord_Style_Font * @var PHPWord_Style_Font
*/ */
private $_styleParagraph; private $_styleParagraph;
/** /**
* Footnote Reference ID * Footnote Reference ID
* *
* @var string * @var string
*/ */
private $_refId; private $_refId;
/** /**
* Text collection * Text collection
* *
* @var array * @var array
*/ */
private $_elementCollection; private $_elementCollection;
/** /**
* Create a new Footnote Element * Create a new Footnote Element
*/ */
public function __construct($styleParagraph = null) { public function __construct($styleParagraph = null)
$this->_elementCollection = array(); {
$this->_elementCollection = array();
// Set paragraph style // Set paragraph style
if(is_array($styleParagraph)) { if (is_array($styleParagraph)) {
$this->_styleParagraph = new PHPWord_Style_Paragraph(); $this->_styleParagraph = new PHPWord_Style_Paragraph();
foreach($styleParagraph as $key => $value) { foreach ($styleParagraph as $key => $value) {
if(substr($key, 0, 1) != '_') { if (substr($key, 0, 1) != '_') {
$key = '_'.$key; $key = '_' . $key;
}
$this->_styleParagraph->setStyleValue($key, $value);
}
} else {
$this->_styleParagraph = $styleParagraph;
} }
$this->_styleParagraph->setStyleValue($key, $value);
}
} else {
$this->_styleParagraph = $styleParagraph;
} }
}
/** /**
* Add a Text Element * Add a Text Element
* *
* @var string $text * @var string $text
* @var mixed $styleFont * @var mixed $styleFont
* @return PHPWord_Section_Text * @return PHPWord_Section_Text
*/ */
public function addText($text = null, $styleFont = null) { public function addText($text = null, $styleFont = null)
$givenText = $text; {
$text = new PHPWord_Section_Text($givenText, $styleFont); $givenText = $text;
$this->_elementCollection[] = $text; $text = new PHPWord_Section_Text($givenText, $styleFont);
return $text; $this->_elementCollection[] = $text;
} return $text;
}
/** /**
* Add a Link Element * Add a Link Element
* *
* @param string $linkSrc * @param string $linkSrc
* @param string $linkName * @param string $linkName
* @param mixed $styleFont * @param mixed $styleFont
* @return PHPWord_Section_Link * @return PHPWord_Section_Link
*/ */
public function addLink($linkSrc, $linkName = null, $styleFont = null) { public function addLink($linkSrc, $linkName = null, $styleFont = null)
{
$link = new PHPWord_Section_Link($linkSrc, $linkName, $styleFont); $link = new PHPWord_Section_Link($linkSrc, $linkName, $styleFont);
$rID = PHPWord_Footnote::addFootnoteLinkElement($linkSrc); $rID = PHPWord_Footnote::addFootnoteLinkElement($linkSrc);
$link->setRelationId($rID); $link->setRelationId($rID);
$this->_elementCollection[] = $link; $this->_elementCollection[] = $link;
return $link; return $link;
} }
/** /**
* Get Footnote content * Get Footnote content
* *
* @return array * @return array
*/ */
public function getElements() { public function getElements()
return $this->_elementCollection; {
} return $this->_elementCollection;
}
/** /**
* Get Paragraph style * Get Paragraph style
* *
* @return PHPWord_Style_Paragraph * @return PHPWord_Style_Paragraph
*/ */
public function getParagraphStyle() { public function getParagraphStyle()
return $this->_styleParagraph; {
} return $this->_styleParagraph;
}
/** /**
* Get Footnote Reference ID * Get Footnote Reference ID
* *
* @return int * @return int
*/ */
public function getReferenceId() { public function getReferenceId()
return $this->_refId; {
} return $this->_refId;
}
/** /**
* Set Footnote Reference ID * Set Footnote Reference ID
* *
* @param int $refId * @param int $refId
*/ */
public function setReferenceId($refId) { public function setReferenceId($refId)
$this->_refId = $refId; {
} $this->_refId = $refId;
} }
}

View File

@ -292,5 +292,4 @@ class PHPWord_Section_Header
{ {
return $this->_type = PHPWord_Section_Header::EVEN; return $this->_type = PHPWord_Section_Header::EVEN;
} }
}
}

View File

@ -175,4 +175,4 @@ class PHPWord_Section_Image
{ {
$this->_isWatermark = $pValue; $this->_isWatermark = $pValue;
} }
} }

View File

@ -616,7 +616,8 @@ class PHPWord_Section_Settings
* *
* @return int * @return int
*/ */
public function getHeaderHeight() { public function getHeaderHeight()
{
return $this->headerHeight; return $this->headerHeight;
} }
@ -625,7 +626,8 @@ class PHPWord_Section_Settings
* *
* @param int $pValue * @param int $pValue
*/ */
public function setHeaderHeight($pValue = '') { public function setHeaderHeight($pValue = '')
{
if (!is_numeric($pValue)) { if (!is_numeric($pValue)) {
$pValue = 720; $pValue = 720;
} }
@ -638,7 +640,8 @@ class PHPWord_Section_Settings
* *
* @return int * @return int
*/ */
public function getFooterHeight() { public function getFooterHeight()
{
return $this->footerHeight; return $this->footerHeight;
} }
@ -647,7 +650,8 @@ class PHPWord_Section_Settings
* *
* @param int $pValue * @param int $pValue
*/ */
public function setFooterHeight($pValue = '') { public function setFooterHeight($pValue = '')
{
if (!is_numeric($pValue)) { if (!is_numeric($pValue)) {
$pValue = 720; $pValue = 720;
} }
@ -660,7 +664,8 @@ class PHPWord_Section_Settings
* *
* @param int $pValue * @param int $pValue
*/ */
public function setColsNum($pValue = '') { public function setColsNum($pValue = '')
{
if (!is_numeric($pValue)) { if (!is_numeric($pValue)) {
$pValue = 1; $pValue = 1;
} }
@ -673,7 +678,8 @@ class PHPWord_Section_Settings
* *
* @return int * @return int
*/ */
public function getColsNum() { public function getColsNum()
{
return $this->_colsNum; return $this->_colsNum;
} }
@ -682,7 +688,8 @@ class PHPWord_Section_Settings
* *
* @param int $pValue * @param int $pValue
*/ */
public function setColsSpace($pValue = '') { public function setColsSpace($pValue = '')
{
if (!is_numeric($pValue)) { if (!is_numeric($pValue)) {
$pValue = 720; $pValue = 720;
} }
@ -695,7 +702,8 @@ class PHPWord_Section_Settings
* *
* @return int * @return int
*/ */
public function getColsSpace() { public function getColsSpace()
{
return $this->_colsSpace; return $this->_colsSpace;
} }
@ -704,7 +712,8 @@ class PHPWord_Section_Settings
* *
* @param string $pValue * @param string $pValue
*/ */
public function setBreakType($pValue = null) { public function setBreakType($pValue = null)
{
$this->_breakType = $pValue; $this->_breakType = $pValue;
return $this; return $this;
} }
@ -714,8 +723,8 @@ class PHPWord_Section_Settings
* *
* @return string * @return string
*/ */
public function getBreakType() { public function getBreakType()
{
return $this->_breakType; return $this->_breakType;
} }
} }

View File

@ -160,5 +160,4 @@ class PHPWord_Section_Table
{ {
return $this->_width; return $this->_width;
} }
} }

View File

@ -333,4 +333,4 @@ class PHPWord_Section_Table_Cell
{ {
return $this->_width; return $this->_width;
} }
} }

View File

@ -138,4 +138,4 @@ class PHPWord_Section_Table_Row
{ {
return $this->_height; return $this->_height;
} }
} }

View File

@ -149,4 +149,4 @@ class PHPWord_Section_Text
{ {
return $this->text; return $this->text;
} }
} }

View File

@ -116,7 +116,8 @@ class PHPWord_Section_TextRun
* @param mixed $styleFont * @param mixed $styleFont
* @return PHPWord_Section_Image * @return PHPWord_Section_Image
*/ */
public function addImage($imageSrc, $style = null) { public function addImage($imageSrc, $style = null)
{
$image = new PHPWord_Section_Image($imageSrc, $style); $image = new PHPWord_Section_Image($imageSrc, $style);
if (!is_null($image->getSource())) { if (!is_null($image->getSource())) {
@ -135,7 +136,8 @@ class PHPWord_Section_TextRun
* *
* @param int $count * @param int $count
*/ */
public function addTextBreak($count = 1) { public function addTextBreak($count = 1)
{
for ($i=1; $i<=$count; $i++) { for ($i=1; $i<=$count; $i++) {
$this->_elementCollection[] = new PHPWord_Section_TextBreak(); $this->_elementCollection[] = new PHPWord_Section_TextBreak();
} }
@ -147,7 +149,8 @@ class PHPWord_Section_TextRun
* @param string $text * @param string $text
* @return PHPWord_Section_Footnote * @return PHPWord_Section_Footnote
*/ */
public function createFootnote($styleParagraph = null) { public function createFootnote($styleParagraph = null)
{
$footnote = new PHPWord_Section_Footnote($styleParagraph); $footnote = new PHPWord_Section_Footnote($styleParagraph);
$refID = PHPWord_Footnote::addFootnoteElement($footnote); $refID = PHPWord_Footnote::addFootnoteElement($footnote);
$footnote->setReferenceId($refID); $footnote->setReferenceId($refID);
@ -174,4 +177,4 @@ class PHPWord_Section_TextRun
{ {
return $this->_styleParagraph; return $this->_styleParagraph;
} }
} }

View File

@ -76,7 +76,7 @@ class PHPWord_Shared_File
// Found something? // Found something?
if ($returnValue == '' || is_null($returnValue)) { if ($returnValue == '' || is_null($returnValue)) {
$pathArray = split('/', $pFilename); $pathArray = explode('/', $pFilename);
while (in_array('..', $pathArray) && $pathArray[0] != '..') { while (in_array('..', $pathArray) && $pathArray[0] != '..') {
for ($i = 0; $i < count($pathArray); ++$i) { for ($i = 0; $i < count($pathArray); ++$i) {
if ($pathArray[$i] == '..' && $i > 0) { if ($pathArray[$i] == '..' && $i > 0) {

View File

@ -88,5 +88,4 @@ class PHPWord_Shared_Font
{ {
return ($sizeInPoint * 20); return ($sizeInPoint * 20);
} }
} }

View File

@ -266,5 +266,4 @@ class PHPWord_Shared_String
$count = strlen($value); $count = strlen($value);
return $count; return $count;
} }
} }

View File

@ -150,4 +150,4 @@ class PHPWord_Shared_XMLWriter
return $this->text($text); return $this->text($text);
} }
} }

View File

@ -121,7 +121,7 @@ class PHPWord_Shared_ZipStreamWrapper
/** /**
* Read stream * Read stream
*/ */
function stream_read($count) public function stream_read($count)
{ {
$ret = substr($this->_data, $this->_position, $count); $ret = substr($this->_data, $this->_position, $count);
$this->_position += strlen($ret); $this->_position += strlen($ret);

View File

@ -175,4 +175,3 @@ class PHPWord_Style
} }
} }
} }

View File

@ -123,7 +123,7 @@ class PHPWord_Style_Cell
* *
* @var integer * @var integer
*/ */
private $_gridSpan = NULL; private $_gridSpan = null;
/** /**
* rowspan (restart, continue) * rowspan (restart, continue)
@ -133,7 +133,7 @@ class PHPWord_Style_Cell
* *
* @var string * @var string
*/ */
private $_vMerge = NULL; private $_vMerge = null;
/** /**
* Create a new Cell Style * Create a new Cell Style
@ -342,4 +342,4 @@ class PHPWord_Style_Cell
{ {
return $this->_vMerge; return $this->_vMerge;
} }
} }

View File

@ -173,4 +173,4 @@ class PHPWord_Style_Image
{ {
return $this->wrappingStyle; return $this->wrappingStyle;
} }
} }

View File

@ -506,4 +506,4 @@ class PHPWord_Style_Paragraph
{ {
return $this->lineHeight; return $this->lineHeight;
} }
} }

View File

@ -81,5 +81,4 @@ class PHPWord_Style_Row
{ {
return $this->_cantSplit ? 1 : 0; return $this->_cantSplit ? 1 : 0;
} }
}
}

View File

@ -92,7 +92,7 @@ class PHPWord_Style_Tab
* @param int $position Must be an integer; otherwise defaults to 0. * @param int $position Must be an integer; otherwise defaults to 0.
* @param string $leader Defaults to NULL if value is not possible. * @param string $leader Defaults to NULL if value is not possible.
*/ */
public function __construct($val = NULL, $position = 0, $leader = NULL) public function __construct($val = null, $position = 0, $leader = null)
{ {
// Default to clear if the stop type is not matched // Default to clear if the stop type is not matched
$this->_val = (self::isStopType($val)) ? $val : 'clear'; $this->_val = (self::isStopType($val)) ? $val : 'clear';
@ -101,7 +101,7 @@ class PHPWord_Style_Tab
$this->_position = (is_numeric($position)) ? intval($position) : 0; $this->_position = (is_numeric($position)) ? intval($position) : 0;
// Default to NULL if no tab leader // Default to NULL if no tab leader
$this->_leader = (self::isLeaderType($leader)) ? $leader : NULL; $this->_leader = (self::isLeaderType($leader)) ? $leader : null;
} }
/** /**
@ -109,7 +109,7 @@ class PHPWord_Style_Tab
* *
* @param PHPWord_Shared_XMLWriter $objWriter * @param PHPWord_Shared_XMLWriter $objWriter
*/ */
public function toXml(PHPWord_Shared_XMLWriter &$objWriter = NULL) public function toXml(PHPWord_Shared_XMLWriter &$objWriter = null)
{ {
if (isset($objWriter)) { if (isset($objWriter)) {
$objWriter->startElement("w:tab"); $objWriter->startElement("w:tab");
@ -143,4 +143,4 @@ class PHPWord_Style_Tab
{ {
return in_array($attribute, self::$_possibleLeaders); return in_array($attribute, self::$_possibleLeaders);
} }
} }

View File

@ -51,7 +51,7 @@ class PHPWord_Style_Tabs
* *
* @param PHPWord_Shared_XMLWriter $objWriter * @param PHPWord_Shared_XMLWriter $objWriter
*/ */
public function toXml(PHPWord_Shared_XMLWriter &$objWriter = NULL) public function toXml(PHPWord_Shared_XMLWriter &$objWriter = null)
{ {
if (isset($objWriter)) { if (isset($objWriter)) {
$objWriter->startElement("w:tabs"); $objWriter->startElement("w:tabs");
@ -61,4 +61,4 @@ class PHPWord_Style_Tabs
$objWriter->endElement(); $objWriter->endElement();
} }
} }
} }

View File

@ -152,4 +152,4 @@ class PHPWord_TOC
{ {
return self::$_styleFont; return self::$_styleFont;
} }
} }

View File

@ -75,7 +75,7 @@ class PHPWord_Template
throw new PHPWord_Exception('Could not create temporary file with unique name in the default temporary directory.'); throw new PHPWord_Exception('Could not create temporary file with unique name in the default temporary directory.');
} }
} }
/** /**
* Applies XSL style sheet to template's parts * Applies XSL style sheet to template's parts
* *
@ -133,10 +133,10 @@ class PHPWord_Template
} }
$replace = htmlspecialchars($replace); $replace = htmlspecialchars($replace);
} else { } else {
foreach($replace as $key=>$value) { foreach ($replace as $key => $value) {
$replace[$key] = htmlspecialchars($value); $replace[$key] = htmlspecialchars($value);
} }
} }
$regExpDelim = '/'; $regExpDelim = '/';
$escapedSearch = preg_quote($search, $regExpDelim); $escapedSearch = preg_quote($search, $regExpDelim);
@ -154,37 +154,40 @@ class PHPWord_Template
/** /**
* Find the start position of the nearest table row before $offset * Find the start position of the nearest table row before $offset
* *
* @param mixed $offset * @param mixed $offset
*/ */
private function _findRowStart($offset) { private function _findRowStart($offset)
$rowStart = strrpos($this->_documentXML, "<w:tr ", ((strlen($this->_documentXML) - $offset) * -1)); {
if (!$rowStart) { $rowStart = strrpos($this->_documentXML, "<w:tr ", ((strlen($this->_documentXML) - $offset) * -1));
$rowStart = strrpos($this->_documentXML, "<w:tr>", ((strlen($this->_documentXML) - $offset) * -1)); if (!$rowStart) {
} $rowStart = strrpos($this->_documentXML, "<w:tr>", ((strlen($this->_documentXML) - $offset) * -1));
if (!$rowStart) { }
trigger_error("Can not find the start position of the row to clone."); if (!$rowStart) {
return false; trigger_error("Can not find the start position of the row to clone.");
} return false;
}
return $rowStart; return $rowStart;
} }
/** /**
* Find the end position of the nearest table row after $offset * Find the end position of the nearest table row after $offset
* *
* @param mixed $offset * @param mixed $offset
*/ */
private function _findRowEnd($offset) { private function _findRowEnd($offset)
$rowEnd = strpos($this->_documentXML, "</w:tr>", $offset) + 7; {
$rowEnd = strpos($this->_documentXML, "</w:tr>", $offset) + 7;
return $rowEnd; return $rowEnd;
} }
/** /**
* Get a slice of a string * Get a slice of a string
* *
* @param mixed $offset * @param mixed $offset
*/ */
private function _getSlice($startPosition, $endPosition = 0) { private function _getSlice($startPosition, $endPosition = 0)
{
if (!$endPosition) { if (!$endPosition) {
$endPosition = strlen($this->_documentXML); $endPosition = strlen($this->_documentXML);
} }
@ -193,38 +196,39 @@ class PHPWord_Template
/** /**
* Clone a table row in a template document * Clone a table row in a template document
* *
* @param mixed $search * @param mixed $search
* @param mixed $numberOfClones * @param mixed $numberOfClones
*/ */
public function cloneRow($search, $numberOfClones) { public function cloneRow($search, $numberOfClones)
if(substr($search, 0, 2) !== '${' && substr($search, -1) !== '}') { {
if (substr($search, 0, 2) !== '${' && substr($search, -1) !== '}') {
$search = '${'.$search.'}'; $search = '${'.$search.'}';
} }
$tagPos = strpos($this->_documentXML, $search); $tagPos = strpos($this->_documentXML, $search);
if (!$tagPos) { if (!$tagPos) {
trigger_error("Can not clone row, template variable not found or variable contains markup."); trigger_error("Can not clone row, template variable not found or variable contains markup.");
return false; return false;
} }
$rowStart = $this->_findRowStart($tagPos); $rowStart = $this->_findRowStart($tagPos);
$rowEnd = $this->_findRowEnd($tagPos); $rowEnd = $this->_findRowEnd($tagPos);
$xmlRow = $this->_getSlice($rowStart, $rowEnd); $xmlRow = $this->_getSlice($rowStart, $rowEnd);
// Check if there's a cell spanning multiple rows. // Check if there's a cell spanning multiple rows.
if (preg_match('#<w:vMerge w:val="restart"/>#', $xmlRow)) { if (preg_match('#<w:vMerge w:val="restart"/>#', $xmlRow)) {
$extraRowStart = $rowEnd; $extraRowStart = $rowEnd;
$extraRowEnd = $rowEnd; $extraRowEnd = $rowEnd;
while(true) { while (true) {
$extraRowStart = $this->_findRowStart($extraRowEnd + 1); $extraRowStart = $this->_findRowStart($extraRowEnd + 1);
$extraRowEnd = $this->_findRowEnd($extraRowEnd + 1); $extraRowEnd = $this->_findRowEnd($extraRowEnd + 1);
// If extraRowEnd is lower then 7, there was no next row found. // If extraRowEnd is lower then 7, there was no next row found.
if ($extraRowEnd < 7) { if ($extraRowEnd < 7) {
break; break;
} }
// If tmpXmlRow doesn't contain continue, this row is no longer part of the spanned row. // If tmpXmlRow doesn't contain continue, this row is no longer part of the spanned row.
$tmpXmlRow = $this->_getSlice($extraRowStart, $extraRowEnd); $tmpXmlRow = $this->_getSlice($extraRowStart, $extraRowEnd);
if (!preg_match('#<w:vMerge/>#', $tmpXmlRow) && !preg_match('#<w:vMerge w:val="continue" />#', $tmpXmlRow)) { if (!preg_match('#<w:vMerge/>#', $tmpXmlRow) && !preg_match('#<w:vMerge w:val="continue" />#', $tmpXmlRow)) {
@ -232,17 +236,17 @@ class PHPWord_Template
} }
// This row was a spanned row, update $rowEnd and search for the next row. // This row was a spanned row, update $rowEnd and search for the next row.
$rowEnd = $extraRowEnd; $rowEnd = $extraRowEnd;
} }
$xmlRow = $this->_getSlice($rowStart, $rowEnd); $xmlRow = $this->_getSlice($rowStart, $rowEnd);
} }
$result = $this->_getSlice(0, $rowStart); $result = $this->_getSlice(0, $rowStart);
for ($i = 1; $i <= $numberOfClones; $i++) { for ($i = 1; $i <= $numberOfClones; $i++) {
$result .= preg_replace('/\$\{(.*?)\}/','\${\\1#'.$i.'}', $xmlRow); $result .= preg_replace('/\$\{(.*?)\}/', '\${\\1#'.$i.'}', $xmlRow);
} }
$result .= $this->_getSlice($rowEnd); $result .= $this->_getSlice($rowEnd);
$this->_documentXML = $result; $this->_documentXML = $result;
} }
/** /**
@ -250,7 +254,8 @@ class PHPWord_Template
* *
* @return string * @return string
*/ */
public function save() { public function save()
{
$this->_objZip->addFromString('word/document.xml', $this->_documentXML); $this->_objZip->addFromString('word/document.xml', $this->_documentXML);
// Close zip file // Close zip file
@ -266,7 +271,8 @@ class PHPWord_Template
* *
* @param string $strFilename * @param string $strFilename
*/ */
public function saveAs($strFilename) { public function saveAs($strFilename)
{
$tempFilename = $this->save(); $tempFilename = $this->save();
if (file_exists($strFilename)) { if (file_exists($strFilename)) {

View File

@ -161,7 +161,7 @@ class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter
} }
$objZip->addFromString('Pictures/' . str_replace(' ', '_', $this->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()), $imageContents); $objZip->addFromString('Pictures/' . str_replace(' ', '_', $this->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()), $imageContents);
} else if ($this->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_MemoryDrawing) { } elseif ($this->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_MemoryDrawing) {
ob_start(); ob_start();
call_user_func( call_user_func(
$this->getDrawingHashTable()->getByIndex($i)->getRenderingFunction(), $this->getDrawingHashTable()->getByIndex($i)->getRenderingFunction(),
@ -236,7 +236,7 @@ class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter
* @param string $pPartName Writer part name * @param string $pPartName Writer part name
* @return PHPWord_Writer_ODText_WriterPart * @return PHPWord_Writer_ODText_WriterPart
*/ */
function getWriterPart($pPartName = '') public function getWriterPart($pPartName = '')
{ {
if ($pPartName != '' && isset($this->_writerParts[strtolower($pPartName)])) { if ($pPartName != '' && isset($this->_writerParts[strtolower($pPartName)])) {
return $this->_writerParts[strtolower($pPartName)]; return $this->_writerParts[strtolower($pPartName)];
@ -287,4 +287,4 @@ class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter
{ {
return $this->_diskCachingDirectory; return $this->_diskCachingDirectory;
} }
} }

View File

@ -249,27 +249,27 @@ class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart
foreach ($_elements as $element) { foreach ($_elements as $element) {
if ($element instanceof PHPWord_Section_Text) { if ($element instanceof PHPWord_Section_Text) {
$this->_writeText($objWriter, $element); $this->_writeText($objWriter, $element);
} elseif($element instanceof PHPWord_Section_TextRun) { } elseif ($element instanceof PHPWord_Section_TextRun) {
$this->_writeTextRun($objWriter, $element); $this->_writeTextRun($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_TextBreak) { } elseif ($element instanceof PHPWord_Section_TextBreak) {
$this->_writeTextBreak($objWriter); $this->_writeTextBreak($objWriter);
/* /*
} elseif($element instanceof PHPWord_Section_Link) { } elseif ($element instanceof PHPWord_Section_Link) {
$this->_writeLink($objWriter, $element); $this->_writeLink($objWriter, $element);
} elseif($element instanceof PHPWord_Section_Title) { } elseif ($element instanceof PHPWord_Section_Title) {
$this->_writeTitle($objWriter, $element); $this->_writeTitle($objWriter, $element);
} elseif($element instanceof PHPWord_Section_PageBreak) { } elseif ($element instanceof PHPWord_Section_PageBreak) {
$this->_writePageBreak($objWriter); $this->_writePageBreak($objWriter);
} elseif($element instanceof PHPWord_Section_Table) { } elseif ($element instanceof PHPWord_Section_Table) {
$this->_writeTable($objWriter, $element); $this->_writeTable($objWriter, $element);
} elseif($element instanceof PHPWord_Section_ListItem) { } elseif ($element instanceof PHPWord_Section_ListItem) {
$this->_writeListItem($objWriter, $element); $this->_writeListItem($objWriter, $element);
} elseif($element instanceof PHPWord_Section_Image || } elseif ($element instanceof PHPWord_Section_Image ||
$element instanceof PHPWord_Section_MemoryImage) { $element instanceof PHPWord_Section_MemoryImage) {
$this->_writeImage($objWriter, $element); $this->_writeImage($objWriter, $element);
} elseif($element instanceof PHPWord_Section_Object) { } elseif ($element instanceof PHPWord_Section_Object) {
$this->_writeObject($objWriter, $element); $this->_writeObject($objWriter, $element);
} elseif($element instanceof PHPWord_TOC) { } elseif ($element instanceof PHPWord_TOC) {
$this->_writeTOC($objWriter); $this->_writeTOC($objWriter);
*/ */
} else { } else {
@ -303,8 +303,8 @@ class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart
protected function _writeText( protected function _writeText(
PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Shared_XMLWriter $objWriter = null,
PHPWord_Section_Text $text, PHPWord_Section_Text $text,
$withoutP = false) $withoutP = false
{ ) {
$styleFont = $text->getFontStyle(); $styleFont = $text->getFontStyle();
$styleParagraph = $text->getParagraphStyle(); $styleParagraph = $text->getParagraphStyle();
@ -351,9 +351,7 @@ class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart
* @param PHPWord_Section_TextRun $textrun * @param PHPWord_Section_TextRun $textrun
* @todo Enable all other section types * @todo Enable all other section types
*/ */
protected function _writeTextRun( protected function _writeTextRun(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_TextRun $textrun)
PHPWord_Shared_XMLWriter $objWriter = null,
PHPWord_Section_TextRun $textrun)
{ {
$elements = $textrun->getElements(); $elements = $textrun->getElements();
$objWriter->startElement('text:p'); $objWriter->startElement('text:p');
@ -377,7 +375,7 @@ class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart
$objWriter->endElement(); $objWriter->endElement();
} }
private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section) private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section = null)
{ {
} }
@ -386,9 +384,7 @@ class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart
* *
* @todo Create the real function * @todo Create the real function
*/ */
private function _writeSection( private function _writeSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section = null)
PHPWord_Shared_XMLWriter $objWriter = null,
PHPWord_Section $section)
{ {
} }
} }

View File

@ -86,7 +86,7 @@ class PHPWord_Writer_ODText_Manifest extends PHPWord_Writer_ODText_WriterPart
$objWriter->writeAttribute('manifest:media-type', $mimeType); $objWriter->writeAttribute('manifest:media-type', $mimeType);
$objWriter->writeAttribute('manifest:full-path', 'Pictures/' . str_replace(' ', '_', $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getIndexedFilename())); $objWriter->writeAttribute('manifest:full-path', 'Pictures/' . str_replace(' ', '_', $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()));
$objWriter->endElement(); $objWriter->endElement();
} else if ($this->getParentWriter()->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_MemoryDrawing) { } elseif ($this->getParentWriter()->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_MemoryDrawing) {
$extension = strtolower($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getMimeType()); $extension = strtolower($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getMimeType());
$extension = explode('/', $extension); $extension = explode('/', $extension);
$extension = $extension[1]; $extension = $extension[1];

View File

@ -42,5 +42,4 @@ class PHPWord_Writer_ODText_Mimetype extends PHPWord_Writer_ODText_WriterPart
return 'application/vnd.oasis.opendocument.text'; return 'application/vnd.oasis.opendocument.text';
} }
} }

View File

@ -182,8 +182,8 @@ class PHPWord_Writer_ODText_Styles extends PHPWord_Writer_ODText_WriterPart
} }
$objWriter->endElement(); $objWriter->endElement();
$objWriter->endElement(); $objWriter->endElement();
} // PHPWord_Style_Paragraph } elseif ($style instanceof PHPWord_Style_Paragraph) {
elseif ($style instanceof PHPWord_Style_Paragraph) { // PHPWord_Style_Paragraph
// style:style // style:style
$objWriter->startElement('style:style'); $objWriter->startElement('style:style');
$objWriter->writeAttribute('style:name', $styleName); $objWriter->writeAttribute('style:name', $styleName);
@ -197,9 +197,8 @@ class PHPWord_Writer_ODText_Styles extends PHPWord_Writer_ODText_WriterPart
$objWriter->endElement(); $objWriter->endElement();
$objWriter->endElement(); $objWriter->endElement();
} elseif ($style instanceof PHPWord_Style_TableFull) {
} // PHPWord_Style_TableFull // PHPWord_Style_TableFull
elseif ($style instanceof PHPWord_Style_TableFull) {
} }
} }
} }

View File

@ -81,7 +81,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
} }
$hFile = fopen($pFilename, 'w') or die("can't open file"); $hFile = fopen($pFilename, 'w') or die("can't open file");
fwrite($hFile, $this->_getData()); fwrite($hFile, $this->getData());
fclose($hFile); fclose($hFile);
// If a temporary file was used, copy it to the correct file stream // If a temporary file was used, copy it to the correct file stream
@ -135,11 +135,11 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
return $this->_drawingHashTable; return $this->_drawingHashTable;
} }
private function _getData() private function getData()
{ {
// PHPWord object : $this->_document // PHPWord object : $this->_document
$this->_fontTable = $this->_getDataFont(); $this->_fontTable = $this->getDataFont();
$this->_colorTable = $this->_getDataColor(); $this->_colorTable = $this->getDataColor();
$sRTFContent = '{\rtf1'; $sRTFContent = '{\rtf1';
// Set the default character set // Set the default character set
@ -180,7 +180,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
$sRTFContent .= '\fs' . (PHPWord::DEFAULT_FONT_SIZE * 2); $sRTFContent .= '\fs' . (PHPWord::DEFAULT_FONT_SIZE * 2);
$sRTFContent .= PHP_EOL; $sRTFContent .= PHP_EOL;
// Body // Body
$sRTFContent .= $this->_getDataContent(); $sRTFContent .= $this->getDataContent();
$sRTFContent .= '}'; $sRTFContent .= '}';
@ -188,7 +188,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
return $sRTFContent; return $sRTFContent;
} }
private function _getDataFont() private function getDataFont()
{ {
$pPHPWord = $this->_document; $pPHPWord = $this->_document;
@ -204,7 +204,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
foreach ($styles as $styleName => $style) { foreach ($styles as $styleName => $style) {
// PHPWord_Style_Font // PHPWord_Style_Font
if ($style instanceof PHPWord_Style_Font) { if ($style instanceof PHPWord_Style_Font) {
if (in_array($style->getName(), $arrFonts) == FALSE) { if (in_array($style->getName(), $arrFonts) == false) {
$arrFonts[] = $style->getName(); $arrFonts[] = $style->getName();
} }
} }
@ -226,7 +226,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
$fStyle = $element->getFontStyle(); $fStyle = $element->getFontStyle();
if ($fStyle instanceof PHPWord_Style_Font) { if ($fStyle instanceof PHPWord_Style_Font) {
if (in_array($fStyle->getName(), $arrFonts) == FALSE) { if (in_array($fStyle->getName(), $arrFonts) == false) {
$arrFonts[] = $fStyle->getName(); $arrFonts[] = $fStyle->getName();
} }
} }
@ -238,7 +238,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
return $arrFonts; return $arrFonts;
} }
private function _getDataColor() private function getDataColor()
{ {
$pPHPWord = $this->_document; $pPHPWord = $this->_document;
@ -254,10 +254,10 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
if ($style instanceof PHPWord_Style_Font) { if ($style instanceof PHPWord_Style_Font) {
$color = $style->getColor(); $color = $style->getColor();
$fgcolor = $style->getFgColor(); $fgcolor = $style->getFgColor();
if (in_array($color, $arrColors) == FALSE && $color != PHPWord::DEFAULT_FONT_COLOR && !empty($color)) { if (in_array($color, $arrColors) == false && $color != PHPWord::DEFAULT_FONT_COLOR && !empty($color)) {
$arrColors[] = $color; $arrColors[] = $color;
} }
if (in_array($fgcolor, $arrColors) == FALSE && $fgcolor != PHPWord::DEFAULT_FONT_COLOR && !empty($fgcolor)) { if (in_array($fgcolor, $arrColors) == false && $fgcolor != PHPWord::DEFAULT_FONT_COLOR && !empty($fgcolor)) {
$arrColors[] = $fgcolor; $arrColors[] = $fgcolor;
} }
} }
@ -279,10 +279,10 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
$fStyle = $element->getFontStyle(); $fStyle = $element->getFontStyle();
if ($fStyle instanceof PHPWord_Style_Font) { if ($fStyle instanceof PHPWord_Style_Font) {
if (in_array($fStyle->getColor(), $arrColors) == FALSE) { if (in_array($fStyle->getColor(), $arrColors) == false) {
$arrColors[] = $fStyle->getColor(); $arrColors[] = $fStyle->getColor();
} }
if (in_array($fStyle->getFgColor(), $arrColors) == FALSE) { if (in_array($fStyle->getFgColor(), $arrColors) == false) {
$arrColors[] = $fStyle->getFgColor(); $arrColors[] = $fStyle->getFgColor();
} }
} }
@ -294,7 +294,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
return $arrColors; return $arrColors;
} }
private function _getDataContent() private function getDataContent()
{ {
$pPHPWord = $this->_document; $pPHPWord = $this->_document;
$sRTFBody = ''; $sRTFBody = '';
@ -309,11 +309,11 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
$_elements = $section->getElements(); $_elements = $section->getElements();
foreach ($_elements as $element) { foreach ($_elements as $element) {
if ($element instanceof PHPWord_Section_Text) { if ($element instanceof PHPWord_Section_Text) {
$sRTFBody .= $this->_getDataContent_writeText($element); $sRTFBody .= $this->getDataContentText($element);
} elseif ($element instanceof PHPWord_Section_TextBreak) { } elseif ($element instanceof PHPWord_Section_TextBreak) {
$sRTFBody .= $this->_getDataContent_writeTextBreak(); $sRTFBody .= $this->getDataContentTextBreak();
} elseif ($element instanceof PHPWord_Section_TextRun) { } elseif ($element instanceof PHPWord_Section_TextRun) {
$sRTFBody .= $this->_getDataContent_writeTextRun($element); $sRTFBody .= $this->getDataContentTextRun($element);
/* /*
} elseif($element instanceof PHPWord_Section_Link) { } elseif($element instanceof PHPWord_Section_Link) {
$this->_writeLink($objWriter, $element); $this->_writeLink($objWriter, $element);
@ -346,7 +346,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
/** /**
* Get text * Get text
*/ */
private function _getDataContent_writeText(PHPWord_Section_Text $text, $withoutP = false) private function getDataContentText(PHPWord_Section_Text $text, $withoutP = false)
{ {
$sRTFText = ''; $sRTFText = '';
@ -384,7 +384,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
if ($styleFont) { if ($styleFont) {
if ($styleFont->getColor() != null) { if ($styleFont->getColor() != null) {
$idxColor = array_search($styleFont->getColor(), $this->_colorTable); $idxColor = array_search($styleFont->getColor(), $this->_colorTable);
if ($idxColor !== FALSE) { if ($idxColor !== false) {
$sRTFText .= '\cf' . ($idxColor + 1); $sRTFText .= '\cf' . ($idxColor + 1);
} }
} else { } else {
@ -392,7 +392,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
} }
if ($styleFont->getName() != null) { if ($styleFont->getName() != null) {
$idxFont = array_search($styleFont->getName(), $this->_fontTable); $idxFont = array_search($styleFont->getName(), $this->_fontTable);
if ($idxFont !== FALSE) { if ($idxFont !== false) {
$sRTFText .= '\f' . $idxFont; $sRTFText .= '\f' . $idxFont;
} }
} else { } else {
@ -437,7 +437,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
/** /**
* Get text run content * Get text run content
*/ */
private function _getDataContent_writeTextRun(PHPWord_Section_TextRun $textrun) private function getDataContentTextRun(PHPWord_Section_TextRun $textrun)
{ {
$sRTFText = ''; $sRTFText = '';
$elements = $textrun->getElements(); $elements = $textrun->getElements();
@ -446,7 +446,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
foreach ($elements as $element) { foreach ($elements as $element) {
if ($element instanceof PHPWord_Section_Text) { if ($element instanceof PHPWord_Section_Text) {
$sRTFText .= '{'; $sRTFText .= '{';
$sRTFText .= $this->_getDataContent_writeText($element, true); $sRTFText .= $this->getDataContentText($element, true);
$sRTFText .= '}' . PHP_EOL; $sRTFText .= '}' . PHP_EOL;
} }
} }
@ -455,12 +455,10 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
return $sRTFText; return $sRTFText;
} }
private function _getDataContent_writeTextBreak() private function getDataContentTextBreak()
{ {
$this->_lastParagraphStyle = ''; $this->_lastParagraphStyle = '';
return '\par' . PHP_EOL; return '\par' . PHP_EOL;
} }
}
}

View File

@ -115,7 +115,8 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter
$footnoteLinks = array(); $footnoteLinks = array();
$_footnoteElements = PHPWord_Footnote::getFootnoteLinkElements(); $_footnoteElements = PHPWord_Footnote::getFootnoteLinkElements();
foreach($_footnoteElements as $element) { // loop through footnote link elements // loop through footnote link elements
foreach ($_footnoteElements as $element) {
$footnoteLinks[] = $element; $footnoteLinks[] = $element;
} }
@ -204,8 +205,9 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter
$imagetype = image_type_to_mime_type($imagedata[2]); $imagetype = image_type_to_mime_type($imagedata[2]);
$imageext = image_type_to_extension($imagedata[2]); $imageext = image_type_to_extension($imagedata[2]);
$imageext = str_replace('.', '', $imageext); $imageext = str_replace('.', '', $imageext);
if ($imageext == 'jpeg') $imageext = 'jpg'; if ($imageext == 'jpeg') {
$imageext = 'jpg';
}
if (!in_array($imagetype, $this->_imageTypes)) { if (!in_array($imagetype, $this->_imageTypes)) {
$this->_imageTypes[$imageext] = $imagetype; $this->_imageTypes[$imageext] = $imagetype;
} }
@ -262,4 +264,4 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter
$this->_chkContentTypes($element['source']); $this->_chkContentTypes($element['source']);
} }
} }
} }

View File

@ -130,8 +130,8 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
protected function _writeParagraphStyle( protected function _writeParagraphStyle(
PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Shared_XMLWriter $objWriter = null,
PHPWord_Style_Paragraph $style, PHPWord_Style_Paragraph $style,
$withoutPPR = false) $withoutPPR = false
{ ) {
$align = $style->getAlign(); $align = $style->getAlign();
$spacing = $style->getSpacing(); $spacing = $style->getSpacing();
$spaceBefore = $style->getSpaceBefore(); $spaceBefore = $style->getSpaceBefore();
@ -880,7 +880,8 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
$objWriter->endElement(); $objWriter->endElement();
} }
protected function _writeFootnote(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Footnote $footnote) { protected function _writeFootnote(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Footnote $footnote)
{
$objWriter->startElement('w:footnote'); $objWriter->startElement('w:footnote');
$objWriter->writeAttribute('w:id', $footnote->getReferenceId()); $objWriter->writeAttribute('w:id', $footnote->getReferenceId());
@ -889,22 +890,22 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
$objWriter->startElement('w:p'); $objWriter->startElement('w:p');
if($SpIsObject) { if ($SpIsObject) {
$this->_writeParagraphStyle($objWriter, $styleParagraph); $this->_writeParagraphStyle($objWriter, $styleParagraph);
} elseif(!$SpIsObject && !is_null($styleParagraph)) { } elseif (!$SpIsObject && !is_null($styleParagraph)) {
$objWriter->startElement('w:pPr'); $objWriter->startElement('w:pPr');
$objWriter->startElement('w:pStyle'); $objWriter->startElement('w:pStyle');
$objWriter->writeAttribute('w:val', $styleParagraph); $objWriter->writeAttribute('w:val', $styleParagraph);
$objWriter->endElement(); $objWriter->endElement();
$objWriter->endElement(); $objWriter->endElement();
} }
$elements = $footnote->getElements(); $elements = $footnote->getElements();
if(count($elements) > 0) { if (count($elements) > 0) {
foreach($elements as $element) { foreach ($elements as $element) {
if($element instanceof PHPWord_Section_Text) { if ($element instanceof PHPWord_Section_Text) {
$this->_writeText($objWriter, $element, true); $this->_writeText($objWriter, $element, true);
} elseif($element instanceof PHPWord_Section_Link) { } elseif ($element instanceof PHPWord_Section_Link) {
$this->_writeLink($objWriter, $element, true); $this->_writeLink($objWriter, $element, true);
} }
} }
@ -914,7 +915,8 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
$objWriter->endElement(); // w:footnote $objWriter->endElement(); // w:footnote
} }
protected function _writeFootnoteReference(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Footnote $footnote, $withoutP = false) { protected function _writeFootnoteReference(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Footnote $footnote, $withoutP = false)
{
if (!$withoutP) { if (!$withoutP) {
$objWriter->startElement('w:p'); $objWriter->startElement('w:p');
} }
@ -931,4 +933,4 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
$objWriter->endElement(); // w:p $objWriter->endElement(); // w:p
} }
} }
} }

View File

@ -50,12 +50,16 @@ class PHPWord_Writer_Word2007_ContentTypes extends PHPWord_Writer_Word2007_Write
// Rels // Rels
$this->_writeDefaultContentType( $this->_writeDefaultContentType(
$objWriter, 'rels', 'application/vnd.openxmlformats-package.relationships+xml' $objWriter,
'rels',
'application/vnd.openxmlformats-package.relationships+xml'
); );
// XML // XML
$this->_writeDefaultContentType( $this->_writeDefaultContentType(
$objWriter, 'xml', 'application/xml' $objWriter,
'xml',
'application/xml'
); );
// Add media content-types // Add media content-types
@ -65,62 +69,88 @@ class PHPWord_Writer_Word2007_ContentTypes extends PHPWord_Writer_Word2007_Write
// Add embedding content-types // Add embedding content-types
if (count($_objectTypes) > 0) { if (count($_objectTypes) > 0) {
$this->_writeDefaultContentType($objWriter, 'bin', 'application/vnd.openxmlformats-officedocument.oleObject'); $this->_writeDefaultContentType(
$objWriter,
'bin',
'application/vnd.openxmlformats-officedocument.oleObject'
);
} }
// DocProps // DocProps
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, '/docProps/app.xml', 'application/vnd.openxmlformats-officedocument.extended-properties+xml' $objWriter,
'/docProps/app.xml',
'application/vnd.openxmlformats-officedocument.extended-properties+xml'
); );
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, '/docProps/core.xml', 'application/vnd.openxmlformats-package.core-properties+xml' $objWriter,
'/docProps/core.xml',
'application/vnd.openxmlformats-package.core-properties+xml'
); );
// Document // Document
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, '/word/document.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml' $objWriter,
'/word/document.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml'
); );
// Styles // Styles
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, '/word/styles.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml' $objWriter,
'/word/styles.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml'
); );
// Numbering // Numbering
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, '/word/numbering.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml' $objWriter,
'/word/numbering.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml'
); );
// Settings // Settings
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, '/word/settings.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml' $objWriter,
'/word/settings.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml'
); );
// Theme1 // Theme1
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, '/word/theme/theme1.xml', 'application/vnd.openxmlformats-officedocument.theme+xml' $objWriter,
'/word/theme/theme1.xml',
'application/vnd.openxmlformats-officedocument.theme+xml'
); );
// WebSettings // WebSettings
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, '/word/webSettings.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml' $objWriter,
'/word/webSettings.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml'
); );
// Font Table // Font Table
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, '/word/fontTable.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml' $objWriter,
'/word/fontTable.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml'
); );
for ($i = 1; $i <= $_cHdrs; $i++) { for ($i = 1; $i <= $_cHdrs; $i++) {
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, '/word/header' . $i . '.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml' $objWriter,
'/word/header' . $i . '.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml'
); );
} }
for ($i = 1; $i <= $_cFtrs; $i++) { for ($i = 1; $i <= $_cFtrs; $i++) {
$this->_writeOverrideContentType( $this->_writeOverrideContentType(
$objWriter, '/word/footer' . $i . '.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml' $objWriter,
'/word/footer' . $i . '.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml'
); );
} }

View File

@ -94,7 +94,7 @@ class PHPWord_Writer_Word2007_Document extends PHPWord_Writer_Word2007_Base
$this->_writeObject($objWriter, $element); $this->_writeObject($objWriter, $element);
} elseif ($element instanceof PHPWord_TOC) { } elseif ($element instanceof PHPWord_TOC) {
$this->_writeTOC($objWriter); $this->_writeTOC($objWriter);
} elseif($element instanceof PHPWord_Section_Footnote) { } elseif ($element instanceof PHPWord_Section_Footnote) {
$this->_writeFootnoteReference($objWriter, $element); $this->_writeFootnoteReference($objWriter, $element);
} }
} }

View File

@ -26,8 +26,10 @@
*/ */
class PHPWord_Writer_Word2007_Footnotes extends PHPWord_Writer_Word2007_Base { class PHPWord_Writer_Word2007_Footnotes extends PHPWord_Writer_Word2007_Base
public function writeFootnotes($allFootnotesCollection) { {
public function writeFootnotes($allFootnotesCollection)
{
// Create XML writer // Create XML writer
$objWriter = null; $objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) { if ($this->getParentWriter()->getUseDiskCaching()) {
@ -40,8 +42,8 @@ class PHPWord_Writer_Word2007_Footnotes extends PHPWord_Writer_Word2007_Base {
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); $objWriter->startDocument('1.0', 'UTF-8', 'yes');
$objWriter->startElement('w:footnotes'); $objWriter->startElement('w:footnotes');
$objWriter->writeAttribute('xmlns:r','http://schemas.openxmlformats.org/officeDocument/2006/relationships'); $objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$objWriter->writeAttribute('xmlns:w','http://schemas.openxmlformats.org/wordprocessingml/2006/main'); $objWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
// write separator and continuation separator // write separator and continuation separator
$objWriter->startElement('w:footnote'); $objWriter->startElement('w:footnote');
@ -67,8 +69,8 @@ class PHPWord_Writer_Word2007_Footnotes extends PHPWord_Writer_Word2007_Base {
$objWriter->endElement(); // w:footnote $objWriter->endElement(); // w:footnote
foreach($allFootnotesCollection as $footnote) { foreach ($allFootnotesCollection as $footnote) {
if($footnote instanceof PHPWord_Section_Footnote) { if ($footnote instanceof PHPWord_Section_Footnote) {
$this->_writeFootnote($objWriter, $footnote); $this->_writeFootnote($objWriter, $footnote);
} }
} }
@ -78,4 +80,4 @@ class PHPWord_Writer_Word2007_Footnotes extends PHPWord_Writer_Word2007_Base {
// Return // Return
return $objWriter->getData(); return $objWriter->getData();
} }
} }

View File

@ -26,64 +26,61 @@
*/ */
class PHPWord_Writer_Word2007_FootnotesRels extends PHPWord_Writer_Word2007_WriterPart { class PHPWord_Writer_Word2007_FootnotesRels extends PHPWord_Writer_Word2007_WriterPart
public function writeFootnotesRels($_relsCollection) { {
// Create XML writer public function writeFootnotesRels($_relsCollection)
$objWriter = null; {
if ($this->getParentWriter()->getUseDiskCaching()) { // Create XML writer
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); $objWriter = null;
} else { if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY); $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
}
// XML header
$objWriter->startDocument('1.0', 'UTF-8', 'yes');
// Relationships
$objWriter->startElement('Relationships');
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
// Relationships to Links
foreach ($_relsCollection as $relation) {
$relationType = $relation['type'];
$relationName = $relation['target'];
$relationId = $relation['rID'];
$targetMode = ($relationType == 'hyperlink') ? 'External' : '';
$this->_writeRelationship($objWriter, $relationId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType, $relationName, $targetMode);
}
$objWriter->endElement();
// Return
return $objWriter->getData();
} }
// XML header private function _writeRelationship(PHPWord_Shared_XMLWriter $objWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '')
$objWriter->startDocument('1.0','UTF-8','yes'); {
if ($pType != '' && $pTarget != '') {
if (strpos($pId, 'rId') === false) {
$pId = 'rId' . $pId;
}
// Relationships // Write relationship
$objWriter->startElement('Relationships'); $objWriter->startElement('Relationship');
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); $objWriter->writeAttribute('Id', $pId);
$objWriter->writeAttribute('Type', $pType);
$objWriter->writeAttribute('Target', $pTarget);
// Relationships to Links if ($pTargetMode != '') {
foreach($_relsCollection as $relation) { $objWriter->writeAttribute('TargetMode', $pTargetMode);
$relationType = $relation['type']; }
$relationName = $relation['target'];
$relationId = $relation['rID'];
$targetMode = ($relationType == 'hyperlink') ? 'External' : '';
$this->_writeRelationship( $objWriter->endElement();
$objWriter, } else {
$relationId, throw new Exception("Invalid parameters passed.");
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/'.$relationType, }
$relationName,
$targetMode
);
} }
}
$objWriter->endElement();
// Return
return $objWriter->getData();
}
private function _writeRelationship(PHPWord_Shared_XMLWriter $objWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '') {
if($pType != '' && $pTarget != '') {
if(strpos($pId, 'rId') === false) {
$pId = 'rId' . $pId;
}
// Write relationship
$objWriter->startElement('Relationship');
$objWriter->writeAttribute('Id', $pId);
$objWriter->writeAttribute('Type', $pType);
$objWriter->writeAttribute('Target', $pTarget);
if($pTargetMode != '') {
$objWriter->writeAttribute('TargetMode', $pTargetMode);
}
$objWriter->endElement();
} else {
throw new Exception("Invalid parameters passed.");
}
}
}

View File

@ -15,6 +15,7 @@ __Want to contribute?__ Fork us!
## Requirements ## Requirements
* PHP version 5.3.0 or higher * PHP version 5.3.0 or higher
* PHP extension [php_zip](http://php.net/manual/en/book.zip.php) enabled
## Installation ## Installation

View File

@ -16,8 +16,14 @@ class AutoloaderTest extends PHPUnit_Framework_TestCase
public function testAutoloadLegacy() public function testAutoloadLegacy()
{ {
$this->assertNull(PHPWord_Autoloader::load('Foo'), 'PHPWord_Autoloader::load() is trying to load classes outside of the PHPWord namespace'); $this->assertNull(
$this->assertTrue(PHPWord_Autoloader::load('PHPWord'), 'PHPWord_Autoloader::load() failed to autoload the PHPWord class'); PHPWord_Autoloader::load('Foo'),
'PHPWord_Autoloader::load() is trying to load classes outside of the PHPWord namespace'
);
$this->assertTrue(
PHPWord_Autoloader::load('PHPWord'),
'PHPWord_Autoloader::load() failed to autoload the PHPWord class'
);
} }
public function testAutoload() public function testAutoload()
@ -25,8 +31,20 @@ class AutoloaderTest extends PHPUnit_Framework_TestCase
$declared = get_declared_classes(); $declared = get_declared_classes();
$declaredCount = count($declared); $declaredCount = count($declared);
Autoloader::autoload('Foo'); Autoloader::autoload('Foo');
$this->assertEquals($declaredCount, count(get_declared_classes()), 'PhpOffice\\PhpWord\\Autoloader::autoload() is trying to load classes outside of the PhpOffice\\PhpWord namespace'); $this->assertEquals(
Autoloader::autoload('PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException'); // TODO change this class to the main PHPWord class when it is namespaced $declaredCount,
$this->assertTrue(in_array('PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException', get_declared_classes()), 'PhpOffice\\PhpWord\\Autoloader::autoload() failed to autoload the PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException class'); count(get_declared_classes()),
'PhpOffice\\PhpWord\\Autoloader::autoload() is trying to load classes ' .
'outside of the PhpOffice\\PhpWord namespace'
);
// TODO change this class to the main PHPWord class when it is namespaced
Autoloader::autoload(
'PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException'
);
$this->assertTrue(
in_array('PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException', get_declared_classes()),
'PhpOffice\\PhpWord\\Autoloader::autoload() failed to autoload the ' .
'PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException class'
);
} }
} }

View File

@ -16,7 +16,11 @@ class IOFactoryTest extends \PHPUnit_Framework_TestCase
{ {
public function testGetSearchLocations() public function testGetSearchLocations()
{ {
$this->assertAttributeEquals(PHPWord_IOFactory::getSearchLocations(), '_searchLocations', 'PHPWord_IOFactory'); $this->assertAttributeEquals(
PHPWord_IOFactory::getSearchLocations(),
'_searchLocations',
'PHPWord_IOFactory'
);
} }
public function testSetSearchLocationsWithArray() public function testSetSearchLocationsWithArray()
@ -38,7 +42,11 @@ class IOFactoryTest extends \PHPUnit_Framework_TestCase
{ {
PHPWord_IOFactory::setSearchLocations(array()); PHPWord_IOFactory::setSearchLocations(array());
PHPWord_IOFactory::addSearchLocation('type', 'location', 'classname'); PHPWord_IOFactory::addSearchLocation('type', 'location', 'classname');
$this->assertAttributeEquals(array(array('type' => 'type', 'path' => 'location', 'class' => 'classname')), '_searchLocations', 'PHPWord_IOFactory'); $this->assertAttributeEquals(
array(array('type' => 'type', 'path' => 'location', 'class' => 'classname')),
'_searchLocations',
'PHPWord_IOFactory'
);
} }
/** /**
@ -57,6 +65,9 @@ class IOFactoryTest extends \PHPUnit_Framework_TestCase
{ {
$oPHPWord = new PHPWord(); $oPHPWord = new PHPWord();
$this->assertEquals(PHPWord_IOFactory::createWriter($oPHPWord, 'Word2007'), new PHPWord_Writer_Word2007($oPHPWord)); $this->assertEquals(
PHPWord_IOFactory::createWriter($oPHPWord, 'Word2007'),
new PHPWord_Writer_Word2007($oPHPWord)
);
} }
} }

View File

@ -25,4 +25,4 @@ class MediaTest extends \PHPUnit_Framework_TestCase
{ {
$this->assertAttributeEquals(PHPWord_Media::getFooterMediaElements(), '_footerMedia', 'PHPWord_Media'); $this->assertAttributeEquals(PHPWord_Media::getFooterMediaElements(), '_footerMedia', 'PHPWord_Media');
} }
} }

View File

@ -0,0 +1,69 @@
<?php
namespace PHPWord\Tests\Reader;
use PHPUnit_Framework_TestCase;
use PHPWord_Reader_Word2007;
use PHPWord_IOFactory;
/**
* Class Word2007Test
*
* @package PHPWord\Tests
*/
class Word2007Test extends \PHPUnit_Framework_TestCase
{
/** @var Test file directory */
private $dir;
/**
* Init
*/
public function tearDown()
{
}
/**
* Test canRead() method
*/
public function testCanRead()
{
$dir = join(
DIRECTORY_SEPARATOR,
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents')
);
$object = new PHPWord_Reader_Word2007;
$file = $dir . DIRECTORY_SEPARATOR . 'reader.docx';
$this->assertTrue($object->canRead($file));
}
/**
* Test canRead() failure
*
* @expectedException Exception
*/
public function testCanReadFailed()
{
$dir = join(
DIRECTORY_SEPARATOR,
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents')
);
$object = new PHPWord_Reader_Word2007;
$file = $dir . DIRECTORY_SEPARATOR . 'foo.docx';
$this->assertFalse($object->canRead($file));
$object = PHPWord_IOFactory::load($file);
}
/**
* Test load document
*/
public function testLoad()
{
$dir = join(
DIRECTORY_SEPARATOR,
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents')
);
$file = $dir . DIRECTORY_SEPARATOR . 'reader.docx';
$object = PHPWord_IOFactory::load($file);
$this->assertInstanceOf('PHPWord', $object);
}
}

View File

@ -26,8 +26,12 @@ class PreserveTextTest extends \PHPUnit_Framework_TestCase
public function testConstructWithArray() public function testConstructWithArray()
{ {
$oPreserveText = new PHPWord_Section_Footer_PreserveText('text', array('align' => 'center'), array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600)); $oPreserveText = new PHPWord_Section_Footer_PreserveText(
'text',
array('align' => 'center'),
array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600)
);
$this->assertInstanceOf('PHPWord_Style_Font', $oPreserveText->getFontStyle()); $this->assertInstanceOf('PHPWord_Style_Font', $oPreserveText->getFontStyle());
$this->assertInstanceOf('PHPWord_Style_Paragraph', $oPreserveText->getParagraphStyle()); $this->assertInstanceOf('PHPWord_Style_Paragraph', $oPreserveText->getParagraphStyle());
} }
} }

View File

@ -87,7 +87,9 @@ class FooterTest extends \PHPUnit_Framework_TestCase
public function testAddMemoryImage() public function testAddMemoryImage()
{ {
$oFooter = new PHPWord_Section_Footer(1); $oFooter = new PHPWord_Section_Footer(1);
$element = $oFooter->addMemoryImage('https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'); $element = $oFooter->addMemoryImage(
'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'
);
$this->assertCount(1, $oFooter->getElements()); $this->assertCount(1, $oFooter->getElements());
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $element); $this->assertInstanceOf('PHPWord_Section_MemoryImage', $element);
@ -118,4 +120,4 @@ class FooterTest extends \PHPUnit_Framework_TestCase
$this->assertInternalType('array', $oFooter->getElements()); $this->assertInternalType('array', $oFooter->getElements());
} }
} }

View File

@ -61,4 +61,4 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase
$oFootnote = new PHPWord_Section_Footnote(); $oFootnote = new PHPWord_Section_Footnote();
$this->assertInternalType('array', $oFootnote->getElements()); $this->assertInternalType('array', $oFootnote->getElements());
} }
} }

View File

@ -83,7 +83,9 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
public function testAddMemoryImage() public function testAddMemoryImage()
{ {
$oHeader = new PHPWord_Section_Header(1); $oHeader = new PHPWord_Section_Header(1);
$element = $oHeader->addMemoryImage('https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'); $element = $oHeader->addMemoryImage(
'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'
);
$this->assertCount(1, $oHeader->getElements()); $this->assertCount(1, $oHeader->getElements());
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $element); $this->assertInstanceOf('PHPWord_Section_MemoryImage', $element);
@ -161,4 +163,4 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($oHeader->getType(), PHPWord_Section_Header::EVEN); $this->assertEquals($oHeader->getType(), PHPWord_Section_Header::EVEN);
} }
} }

View File

@ -28,7 +28,11 @@ class ImageTest extends \PHPUnit_Framework_TestCase
\DIRECTORY_SEPARATOR, \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'firefox.png') array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'firefox.png')
); );
$oImage = new PHPWord_Section_Image($src, array('width' => 210, 'height' => 210, 'align' => 'center', 'wrappingStyle' => \PHPWord_Style_Image::WRAPPING_STYLE_BEHIND)); $oImage = new PHPWord_Section_Image(
$src,
array('width' => 210, 'height' => 210, 'align' => 'center',
'wrappingStyle' => \PHPWord_Style_Image::WRAPPING_STYLE_BEHIND)
);
$this->assertInstanceOf('PHPWord_Style_Image', $oImage->getStyle()); $this->assertInstanceOf('PHPWord_Style_Image', $oImage->getStyle());
} }
@ -91,4 +95,4 @@ class ImageTest extends \PHPUnit_Framework_TestCase
$oImage->setIsWatermark(true); $oImage->setIsWatermark(true);
$this->assertEquals($oImage->getIsWatermark(), true); $this->assertEquals($oImage->getIsWatermark(), true);
} }
} }

View File

@ -20,7 +20,12 @@ class LinkTest extends \PHPUnit_Framework_TestCase
public function testConstructWithParamsArray() public function testConstructWithParamsArray()
{ {
$oLink = new PHPWord_Section_Link('http://www.google.com', 'Search Engine', array('color' => '0000FF', 'underline' => PHPWord_Style_Font::UNDERLINE_SINGLE), array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600)); $oLink = new PHPWord_Section_Link(
'http://www.google.com',
'Search Engine',
array('color' => '0000FF', 'underline' => PHPWord_Style_Font::UNDERLINE_SINGLE),
array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600)
);
$this->assertInstanceOf('PHPWord_Section_Link', $oLink); $this->assertInstanceOf('PHPWord_Section_Link', $oLink);
$this->assertEquals($oLink->getLinkSrc(), 'http://www.google.com'); $this->assertEquals($oLink->getLinkSrc(), 'http://www.google.com');
@ -45,4 +50,4 @@ class LinkTest extends \PHPUnit_Framework_TestCase
$oLink->setRelationId($iVal); $oLink->setRelationId($iVal);
$this->assertEquals($oLink->getRelationId(), $iVal); $this->assertEquals($oLink->getRelationId(), $iVal);
} }
} }

View File

@ -16,7 +16,12 @@ class ListItemTest extends \PHPUnit_Framework_TestCase
public function testStyle() public function testStyle()
{ {
$oListItem = new PHPWord_Section_ListItem('text', 1, null, array('listType' => PHPWord_Style_ListItem::TYPE_NUMBER)); $oListItem = new PHPWord_Section_ListItem(
'text',
1,
null,
array('listType' => PHPWord_Style_ListItem::TYPE_NUMBER)
);
$this->assertInstanceOf('PHPWord_Style_ListItem', $oListItem->getStyle()); $this->assertInstanceOf('PHPWord_Style_ListItem', $oListItem->getStyle());
$this->assertEquals($oListItem->getStyle()->getListType(), PHPWord_Style_ListItem::TYPE_NUMBER); $this->assertEquals($oListItem->getStyle()->getListType(), PHPWord_Style_ListItem::TYPE_NUMBER);
@ -29,4 +34,4 @@ class ListItemTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($oListItem->getDepth(), $iVal); $this->assertEquals($oListItem->getDepth(), $iVal);
} }
} }

View File

@ -92,4 +92,4 @@ class MemoryImageTest extends \PHPUnit_Framework_TestCase
$oMemoryImage->setRelationId($iVal); $oMemoryImage->setRelationId($iVal);
$this->assertEquals($oMemoryImage->getRelationId(), $iVal); $this->assertEquals($oMemoryImage->getRelationId(), $iVal);
} }
} }

View File

@ -83,4 +83,4 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
$oObject->setObjectId($iVal); $oObject->setObjectId($iVal);
$this->assertEquals($oObject->getObjectId(), $iVal); $this->assertEquals($oObject->getObjectId(), $iVal);
} }
} }

View File

@ -16,4 +16,4 @@ class PageBreakTest extends \PHPUnit_Framework_TestCase
$this->assertInstanceOf('PHPWord_Section_PageBreak', $oPageBreak); $this->assertInstanceOf('PHPWord_Section_PageBreak', $oPageBreak);
} }
} }

View File

@ -233,4 +233,4 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
$oSettings->setBreakType(); $oSettings->setBreakType();
$this->assertNull($oSettings->getBreakType()); $this->assertNull($oSettings->getBreakType());
} }
} }

View File

@ -130,7 +130,9 @@ class CellTest extends \PHPUnit_Framework_TestCase
public function testAddMemoryImageSection() public function testAddMemoryImageSection()
{ {
$oCell = new PHPWord_Section_Table_Cell('section', 1); $oCell = new PHPWord_Section_Table_Cell('section', 1);
$element = $oCell->addMemoryImage('https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'); $element = $oCell->addMemoryImage(
'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'
);
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $element); $this->assertInstanceOf('PHPWord_Section_MemoryImage', $element);
@ -139,7 +141,9 @@ class CellTest extends \PHPUnit_Framework_TestCase
public function testAddMemoryImageHeader() public function testAddMemoryImageHeader()
{ {
$oCell = new PHPWord_Section_Table_Cell('header', 1); $oCell = new PHPWord_Section_Table_Cell('header', 1);
$element = $oCell->addMemoryImage('https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'); $element = $oCell->addMemoryImage(
'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'
);
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $element); $this->assertInstanceOf('PHPWord_Section_MemoryImage', $element);
@ -148,7 +152,9 @@ class CellTest extends \PHPUnit_Framework_TestCase
public function testAddMemoryImageFooter() public function testAddMemoryImageFooter()
{ {
$oCell = new PHPWord_Section_Table_Cell('footer', 1); $oCell = new PHPWord_Section_Table_Cell('footer', 1);
$element = $oCell->addMemoryImage('https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'); $element = $oCell->addMemoryImage(
'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'
);
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $element); $this->assertInstanceOf('PHPWord_Section_MemoryImage', $element);
@ -201,4 +207,4 @@ class CellTest extends \PHPUnit_Framework_TestCase
$this->assertInternalType('array', $oCell->getElements()); $this->assertInternalType('array', $oCell->getElements());
} }
} }

View File

@ -22,7 +22,12 @@ class RowTest extends \PHPUnit_Framework_TestCase
{ {
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$iVal2 = rand(1, 1000); $iVal2 = rand(1, 1000);
$oRow = new PHPWord_Section_Table_Row('section', $iVal, $iVal2, array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF')); $oRow = new PHPWord_Section_Table_Row(
'section',
$iVal,
$iVal2,
array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF')
);
$this->assertEquals($oRow->getHeight(), $iVal2); $this->assertEquals($oRow->getHeight(), $iVal2);
$this->assertInstanceOf('PHPWord_Style_Row', $oRow->getStyle()); $this->assertInstanceOf('PHPWord_Style_Row', $oRow->getStyle());
@ -36,4 +41,4 @@ class RowTest extends \PHPUnit_Framework_TestCase
$this->assertInstanceOf('PHPWord_Section_Table_Cell', $element); $this->assertInstanceOf('PHPWord_Section_Table_Cell', $element);
$this->assertCount(1, $oRow->getCells()); $this->assertCount(1, $oRow->getCells());
} }
} }

View File

@ -26,7 +26,11 @@ class TableTest extends \PHPUnit_Framework_TestCase
public function testStyleArray() public function testStyleArray()
{ {
$oTable = new PHPWord_Section_Table('section', 1, array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80)); $oTable = new PHPWord_Section_Table(
'section',
1,
array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80)
);
$this->assertInstanceOf('PHPWord_Style_Table', $oTable->getStyle()); $this->assertInstanceOf('PHPWord_Style_Table', $oTable->getStyle());
} }
@ -54,4 +58,4 @@ class TableTest extends \PHPUnit_Framework_TestCase
$element = $oTable->addCell(); $element = $oTable->addCell();
$this->assertInstanceOf('PHPWord_Section_Table_Cell', $element); $this->assertInstanceOf('PHPWord_Section_Table_Cell', $element);
} }
} }

View File

@ -16,4 +16,4 @@ class TextBreakTest extends \PHPUnit_Framework_TestCase
$this->assertInstanceOf('PHPWord_Section_TextBreak', $oTextBreak); $this->assertInstanceOf('PHPWord_Section_TextBreak', $oTextBreak);
} }
} }

View File

@ -95,4 +95,4 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
$this->assertInstanceOf('PHPWord_Section_Footnote', $element); $this->assertInstanceOf('PHPWord_Section_Footnote', $element);
$this->assertCount(1, $oTextRun->getElements()); $this->assertCount(1, $oTextRun->getElements());
} }
} }

View File

@ -40,4 +40,4 @@ class TextTest extends \PHPUnit_Framework_TestCase
$oText->setParagraphStyle(array('align' => 'center', 'spaceAfter' => 100)); $oText->setParagraphStyle(array('align' => 'center', 'spaceAfter' => 100));
$this->assertInstanceOf('PHPWord_Style_Paragraph', $oText->getParagraphStyle()); $this->assertInstanceOf('PHPWord_Style_Paragraph', $oText->getParagraphStyle());
} }
} }

View File

@ -45,4 +45,4 @@ class TitleTest extends \PHPUnit_Framework_TestCase
$oTitle->setBookmarkId($iVal); $oTitle->setBookmarkId($iVal);
$this->assertEquals($oTitle->getBookmarkId(), $iVal); $this->assertEquals($oTitle->getBookmarkId(), $iVal);
} }
} }

View File

@ -35,4 +35,4 @@ class SectionTest extends \PHPUnit_Framework_TestCase
$oSection = new PHPWord_Section(0); $oSection = new PHPWord_Section(0);
$this->assertAttributeEquals($oSection->getElements(), '_elementCollection', new PHPWord_Section(0)); $this->assertAttributeEquals($oSection->getElements(), '_elementCollection', new PHPWord_Section(0));
} }
} }

View File

@ -12,7 +12,6 @@ use PHPWord_Shared_Drawing;
*/ */
class DrawingTest extends \PHPUnit_Framework_TestCase class DrawingTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* Test unit conversion functions with various numbers * Test unit conversion functions with various numbers
*/ */
@ -65,5 +64,4 @@ class DrawingTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($value[1], $result); $this->assertEquals($value[1], $result);
} }
} }
}
}

View File

@ -12,13 +12,13 @@ use PHPWord_Shared_File;
*/ */
class FileTest extends \PHPUnit_Framework_TestCase class FileTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* Test file_exists() * Test file_exists()
*/ */
public function testFile_exists() public function testFileExists()
{ {
$dir = join(DIRECTORY_SEPARATOR, $dir = join(
DIRECTORY_SEPARATOR,
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'templates') array(PHPWORD_TESTS_DIR_ROOT, '_files', 'templates')
); );
chdir($dir); chdir($dir);
@ -30,12 +30,13 @@ class FileTest extends \PHPUnit_Framework_TestCase
*/ */
public function testRealpath() public function testRealpath()
{ {
$dir = join(DIRECTORY_SEPARATOR, $dir = join(
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'templates')); DIRECTORY_SEPARATOR,
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'templates')
);
chdir($dir); chdir($dir);
$file = 'blank.docx'; $file = 'blank.docx';
$expected = $dir . DIRECTORY_SEPARATOR . $file; $expected = $dir . DIRECTORY_SEPARATOR . $file;
$this->assertEquals($expected, PHPWord_Shared_File::realpath($file)); $this->assertEquals($expected, PHPWord_Shared_File::realpath($file));
} }
} }

View File

@ -43,4 +43,4 @@ class FontTest extends \PHPUnit_Framework_TestCase
$result = PHPWord_Shared_Font::pointSizeToTwips($original); $result = PHPWord_Shared_Font::pointSizeToTwips($original);
$this->assertEquals($original * 20, $result); $this->assertEquals($original * 20, $result);
} }
} }

View File

@ -12,7 +12,6 @@ use PHPWord_Shared_String;
*/ */
class StringTest extends \PHPUnit_Framework_TestCase class StringTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* Test getIsMbstringEnabled() and getIsIconvEnabled() * Test getIsMbstringEnabled() and getIsIconvEnabled()
*/ */
@ -41,5 +40,4 @@ class StringTest extends \PHPUnit_Framework_TestCase
$returned = PHPWord_Shared_String::FormatNumber('1022.1234'); $returned = PHPWord_Shared_String::FormatNumber('1022.1234');
$this->assertEquals($expected, $returned); $this->assertEquals($expected, $returned);
} }
} }

View File

@ -12,7 +12,6 @@ use PHPWord_Style_Cell;
*/ */
class CellTest extends \PHPUnit_Framework_TestCase class CellTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* Test setting style with normal value * Test setting style with normal value
*/ */
@ -75,4 +74,4 @@ class CellTest extends \PHPUnit_Framework_TestCase
$object->setStyleValue('_borderSize', $value); $object->setStyleValue('_borderSize', $value);
$this->assertEquals($expected, $object->getBorderSize()); $this->assertEquals($expected, $object->getBorderSize());
} }
} }

View File

@ -114,4 +114,4 @@ class FontTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(720, $lineHeight); $this->assertEquals(720, $lineHeight);
$this->assertEquals('auto', $lineRule); $this->assertEquals('auto', $lineRule);
} }
} }

View File

@ -12,7 +12,6 @@ use PHPWord_Style_Image;
*/ */
class ImageTest extends \PHPUnit_Framework_TestCase class ImageTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* Test setting style with normal value * Test setting style with normal value
*/ */
@ -67,5 +66,4 @@ class ImageTest extends \PHPUnit_Framework_TestCase
$object = new PHPWord_Style_Image(); $object = new PHPWord_Style_Image();
$object->setWrappingStyle('foo'); $object->setWrappingStyle('foo');
} }
}
}

View File

@ -12,7 +12,6 @@ use PHPWord_Style_ListItem;
*/ */
class ListItemTest extends \PHPUnit_Framework_TestCase class ListItemTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* Test construct * Test construct
*/ */
@ -47,5 +46,4 @@ class ListItemTest extends \PHPUnit_Framework_TestCase
$object->setListType($value); $object->setListType($value);
$this->assertEquals($value, $object->getListType()); $this->assertEquals($value, $object->getListType());
} }
}
}

View File

@ -133,5 +133,4 @@ class ParagraphTest extends \PHPUnit_Framework_TestCase
$object->setLineHeight('12.5pt'); $object->setLineHeight('12.5pt');
$this->assertEquals(12.5, $object->getLineHeight()); $this->assertEquals(12.5, $object->getLineHeight());
} }
}
}

View File

@ -12,7 +12,6 @@ use PHPWord_Style_Row;
*/ */
class RowTest extends \PHPUnit_Framework_TestCase class RowTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* Test properties with normal value * Test properties with normal value
*/ */
@ -39,5 +38,4 @@ class RowTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($expected, $object->$get()); $this->assertEquals($expected, $object->$get());
} }
} }
} }

View File

@ -12,7 +12,6 @@ use PHPWord_Style_TOC;
*/ */
class TOCTest extends \PHPUnit_Framework_TestCase class TOCTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* Test properties with normal value * Test properties with normal value
*/ */
@ -37,5 +36,4 @@ class TOCTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(null, $object->$get()); $this->assertEquals(null, $object->$get());
} }
} }
} }

View File

@ -12,7 +12,6 @@ use PHPWord_Style_TableFull;
*/ */
class TableFullTest extends \PHPUnit_Framework_TestCase class TableFullTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* Test class construction * Test class construction
* *
@ -132,5 +131,4 @@ class TableFullTest extends \PHPUnit_Framework_TestCase
} }
$this->assertEquals($values, $object->getCellMargin()); $this->assertEquals($values, $object->getCellMargin());
} }
} }

View File

@ -12,7 +12,6 @@ use PHPWord_Style_Table;
*/ */
class TableTest extends \PHPUnit_Framework_TestCase class TableTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* Test set style value * Test set style value
*/ */
@ -50,5 +49,4 @@ class TableTest extends \PHPUnit_Framework_TestCase
} }
$this->assertEquals($values, $object->getCellMargin()); $this->assertEquals($values, $object->getCellMargin());
} }
} }

View File

@ -42,5 +42,4 @@ class TabsTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(1440, $element->getAttribute('w:pos')); $this->assertEquals(1440, $element->getAttribute('w:pos'));
$this->assertEquals('dot', $element->getAttribute('w:leader')); $this->assertEquals('dot', $element->getAttribute('w:leader'));
} }
} }

72
Tests/PHPWord/TOCTest.php Normal file
View File

@ -0,0 +1,72 @@
<?php
namespace PHPWord\Tests;
use PHPUnit_Framework_TestCase;
use PHPWord_TOC;
use PHPWord_Style_TOC;
/**
* @covers PHPWord_TOC
*/
class TOCTest extends PHPUnit_Framework_TestCase
{
/**
* @covers PHPWord_TOC::__construct
* @covers PHPWord_TOC::getStyleTOC
* @covers PHPWord_TOC::getStyleFont
*/
public function testConstruct()
{
$expected = array(
'tabPos' => 9062,
'tabLeader' => PHPWord_Style_TOC::TABLEADER_DOT,
'indent' => 200,
);
$object = new PHPWord_TOC(
array('size' => 11),
array('tabPos' => $expected['tabPos'])
);
$tocStyle = $object->getStyleTOC();
$this->assertInstanceOf('PHPWord_Style_TOC', $tocStyle);
$this->assertInstanceOf('PHPWord_Style_Font', $object->getStyleFont());
foreach ($expected as $key => $value) {
$method = "get{$key}";
$this->assertEquals($value, $tocStyle->$method());
}
}
/**
* @covers PHPWord_TOC::addTitle
* @covers PHPWord_TOC::getTitles
*/
public function testAddAndGetTitle()
{
// Prepare variables
$titleCount = 3;
$anchor = '_Toc' . (252634154 + $titleCount);
$bookmark = $titleCount - 1; // zero based
$titles = array(
'Heading 1' => 1,
'Heading 2' => 2,
'Heading 3' => 3,
);
// @covers PHPWord_TOC::addTitle
foreach ($titles as $text => $depth) {
$response = PHPWord_TOC::addTitle($text, $depth);
}
$this->assertEquals($anchor, $response[0]);
$this->assertEquals($bookmark, $response[1]);
// @covers PHPWord_TOC::getTitles
$i = 0;
$savedTitles = PHPWord_TOC::getTitles();
foreach ($titles as $text => $depth) {
$this->assertEquals($text, $savedTitles[$i]['text']);
$this->assertEquals($depth, $savedTitles[$i]['depth']);
$i++;
}
}
}

View File

@ -115,4 +115,4 @@ class TemplateTest extends \PHPUnit_Framework_TestCase
*/ */
@$template->applyXslStyleSheet($xslDOMDocument); @$template->applyXslStyleSheet($xslDOMDocument);
} }
} }

View File

@ -0,0 +1,88 @@
<?php
namespace PHPWord\Tests\Writer;
use PHPUnit_Framework_TestCase;
use PHPWord_Writer_ODText;
use PHPWord;
/**
* Class ODTextTest
*
* @package PHPWord\Tests
* @runTestsInSeparateProcesses
*/
class ODTextTest extends \PHPUnit_Framework_TestCase
{
/**
* Test construct
*/
public function testConstruct()
{
$object = new PHPWord_Writer_ODText(new PHPWord());
$this->assertInstanceOf('PHPWord', $object->getPHPWord());
$this->assertInstanceOf("PHPWord_HashTable", $object->getDrawingHashTable());
$this->assertEquals('./', $object->getDiskCachingDirectory());
$writerParts = array('Content', 'Manifest', 'Meta', 'Mimetype', 'Styles');
foreach ($writerParts as $part) {
$this->assertInstanceOf(
"PHPWord_Writer_ODText_{$part}",
$object->getWriterPart($part)
);
$this->assertInstanceOf(
"PHPWord_Writer_ODText",
$object->getWriterPart($part)->getParentWriter()
);
}
}
/**
* Test construct with null value/without PHPWord
*
* @expectedException Exception
* @expectedExceptionMessage No PHPWord assigned.
*/
public function testConstructWithNull()
{
$object = new PHPWord_Writer_ODText();
$object->getPHPWord();
}
/**
* Test save()
*/
public function testSave()
{
$phpWord = new PHPWord();
$phpWord->addFontStyle('Font', array('size' => 11));
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));
$section = $phpWord->createSection();
$section->addText('Test 1', 'Font', 'Paragraph');
$section->addTextBreak();
$section->addText('Test 2');
$section = $phpWord->createSection();
$textrun = $section->createTextRun();
$textrun->addText('Test 3');
$writer = new PHPWord_Writer_ODText($phpWord);
$file = join(
DIRECTORY_SEPARATOR,
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'temp.odt')
);
$writer->save($file);
$this->assertTrue(file_exists($file));
unlink($file);
}
/**
* Test disk caching parameters
*/
public function testSetDiskCaching()
{
$object = new PHPWord_Writer_ODText();
$object->setUseDiskCaching(true, PHPWORD_TESTS_DIR_ROOT);
$this->assertTrue($object->getUseDiskCaching());
$this->assertEquals(PHPWORD_TESTS_DIR_ROOT, $object->getDiskCachingDirectory());
}
}

View File

@ -0,0 +1,63 @@
<?php
namespace PHPWord\Tests\Writer;
use PHPUnit_Framework_TestCase;
use PHPWord_Writer_RTF;
use PHPWord;
/**
* Class RTFTest
* @package PHPWord\Tests
* @runTestsInSeparateProcesses
*/
class RTFTest extends \PHPUnit_Framework_TestCase
{
/**
* Test construct
*/
public function testConstruct()
{
$object = new PHPWord_Writer_RTF(new PHPWord);
$this->assertInstanceOf('PHPWord', $object->getPHPWord());
$this->assertInstanceOf("PHPWord_HashTable", $object->getDrawingHashTable());
}
/**
* Test construct with null value/without PHPWord
*
* @expectedException Exception
* @expectedExceptionMessage No PHPWord assigned.
*/
public function testConstructWithNull()
{
$object = new PHPWord_Writer_RTF();
$object->getPHPWord();
}
/**
* Test save()
*/
public function testSave()
{
$phpWord = new PHPWord();
$phpWord->addFontStyle('Font', array('size' => 11));
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));
$section = $phpWord->createSection();
$section->addText('Test 1', 'Font', 'Paragraph');
$section->addTextBreak();
$section->addText('Test 2');
$section = $phpWord->createSection();
$textrun = $section->createTextRun();
$textrun->addText('Test 3');
$writer = new PHPWord_Writer_RTF($phpWord);
$file = join(
DIRECTORY_SEPARATOR,
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'temp.rtf')
);
$writer->save($file);
$this->assertTrue(file_exists($file));
unlink($file);
}
}

View File

@ -20,29 +20,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
TestHelperDOCX::clear(); TestHelperDOCX::clear();
} }
public function testWriteImage_Position() public function testWriteParagraphStyleAlign()
{
$PHPWord = new PHPWord();
$section = $PHPWord->createSection();
$section->addImage(
PHPWORD_TESTS_DIR_ROOT . '/_files/images/earth.jpg',
array(
'marginTop' => -1,
'marginLeft' => -1,
'wrappingStyle' => 'behind'
)
);
$doc = TestHelperDOCX::getDocument($PHPWord);
$element = $doc->getElement('/w:document/w:body/w:p/w:r/w:pict/v:shape');
$style = $element->getAttribute('style');
$this->assertRegExp('/z\-index:\-[0-9]*/', $style);
$this->assertRegExp('/position:absolute;/', $style);
}
public function testWriteParagraphStyle_Align()
{ {
$PHPWord = new PHPWord(); $PHPWord = new PHPWord();
$section = $PHPWord->createSection(); $section = $PHPWord->createSection();
@ -55,34 +33,10 @@ class BaseTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('right', $element->getAttribute('w:val')); $this->assertEquals('right', $element->getAttribute('w:val'));
} }
public function testWriteCellStyle_CellGridSpan()
{
$PHPWord = new PHPWord();
$section = $PHPWord->createSection();
$table = $section->addTable();
$table->addRow();
$cell = $table->addCell(200);
$cell->getStyle()->setGridSpan(5);
$table->addRow();
$table->addCell(40);
$table->addCell(40);
$table->addCell(40);
$table->addCell(40);
$table->addCell(40);
$doc = TestHelperDOCX::getDocument($PHPWord);
$element = $doc->getElement('/w:document/w:body/w:tbl/w:tr/w:tc/w:tcPr/w:gridSpan');
$this->assertEquals(5, $element->getAttribute('w:val'));
}
/** /**
* Test write paragraph pagination * Test write paragraph pagination
*/ */
public function testWriteParagraphStyle_Pagination() public function testWriteParagraphStylePagination()
{ {
// Create the doc // Create the doc
$PHPWord = new PHPWord(); $PHPWord = new PHPWord();
@ -109,6 +63,52 @@ class BaseTest extends \PHPUnit_Framework_TestCase
} }
} }
public function testWriteCellStyleCellGridSpan()
{
$PHPWord = new PHPWord();
$section = $PHPWord->createSection();
$table = $section->addTable();
$table->addRow();
$cell = $table->addCell(200);
$cell->getStyle()->setGridSpan(5);
$table->addRow();
$table->addCell(40);
$table->addCell(40);
$table->addCell(40);
$table->addCell(40);
$table->addCell(40);
$doc = TestHelperDOCX::getDocument($PHPWord);
$element = $doc->getElement('/w:document/w:body/w:tbl/w:tr/w:tc/w:tcPr/w:gridSpan');
$this->assertEquals(5, $element->getAttribute('w:val'));
}
public function testWriteImagePosition()
{
$PHPWord = new PHPWord();
$section = $PHPWord->createSection();
$section->addImage(
PHPWORD_TESTS_DIR_ROOT . '/_files/images/earth.jpg',
array(
'marginTop' => -1,
'marginLeft' => -1,
'wrappingStyle' => 'behind'
)
);
$doc = TestHelperDOCX::getDocument($PHPWord);
$element = $doc->getElement('/w:document/w:body/w:p/w:r/w:pict/v:shape');
$style = $element->getAttribute('style');
$this->assertRegExp('/z\-index:\-[0-9]*/', $style);
$this->assertRegExp('/position:absolute;/', $style);
}
public function testWritePreserveText() public function testWritePreserveText()
{ {
$PHPWord = new PHPWord(); $PHPWord = new PHPWord();
@ -123,4 +123,4 @@ class BaseTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('PAGE', $preserve->nodeValue); $this->assertEquals('PAGE', $preserve->nodeValue);
$this->assertEquals('preserve', $preserve->getAttribute('xml:space')); $this->assertEquals('preserve', $preserve->getAttribute('xml:space'));
} }
} }

View File

@ -22,7 +22,7 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
TestHelperDOCX::clear(); TestHelperDOCX::clear();
} }
public function testWriteEndSection_PageNumbering() public function testWriteEndSectionPageNumbering()
{ {
$PHPWord = new PHPWord(); $PHPWord = new PHPWord();
$section = $PHPWord->createSection(); $section = $PHPWord->createSection();
@ -33,4 +33,4 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(2, $element->getAttribute('w:start')); $this->assertEquals(2, $element->getAttribute('w:start'));
} }
} }

View File

@ -51,4 +51,4 @@ class StylesTest extends \PHPUnit_Framework_TestCase
$element = $doc->getElement($path, $file); $element = $doc->getElement($path, $file);
$this->assertEquals('Normal', $element->getAttribute('w:val')); $this->assertEquals('Normal', $element->getAttribute('w:val'));
} }
} }

View File

@ -0,0 +1,63 @@
<?php
namespace PHPWord\Tests\Writer;
use PHPUnit_Framework_TestCase;
use PHPWord_Writer_Word2007;
use PHPWord;
/**
* Class Word2007Test
*
* @package PHPWord\Tests
* @runTestsInSeparateProcesses
*/
class Word2007Test extends \PHPUnit_Framework_TestCase
{
/**
* Test construct
*/
public function testConstruct()
{
$object = new PHPWord_Writer_Word2007(new PHPWord());
$writerParts = array('ContentTypes', 'Rels', 'DocProps',
'DocumentRels', 'Document', 'Styles', 'Header', 'Footer',
'Footnotes', 'FootnotesRels');
foreach ($writerParts as $part) {
$this->assertInstanceOf(
"PHPWord_Writer_Word2007_{$part}",
$object->getWriterPart($part)
);
$this->assertInstanceOf(
"PHPWord_Writer_Word2007",
$object->getWriterPart($part)->getParentWriter()
);
}
}
/**
* Test save()
*/
public function testSave()
{
$phpWord = new PHPWord();
$phpWord->addFontStyle('Font', array('size' => 11));
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));
$section = $phpWord->createSection();
$section->addText('Test 1', 'Font', 'Paragraph');
$section->addTextBreak();
$section->addText('Test 2');
$section = $phpWord->createSection();
$textrun = $section->createTextRun();
$textrun->addText('Test 3');
$writer = new PHPWord_Writer_Word2007($phpWord);
$file = join(
DIRECTORY_SEPARATOR,
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'temp.docx')
);
$writer->save($file);
$this->assertTrue(file_exists($file));
unlink($file);
}
}

Binary file not shown.

View File

@ -2,15 +2,15 @@
namespace PHPWord\Tests; namespace PHPWord\Tests;
use PHPWord; use PHPWord;
use DOMDocument;
class TestHelperDOCX class TestHelperDOCX
{ {
/** @var string $file */
static protected $file; static protected $file;
/** /**
* @param \PHPWord $PHPWord * @param \PHPWord $PHPWord
* @return \PHPWord\Tests\Xml_Document * @return \PHPWord\Tests\XmlDocument
*/ */
public static function getDocument(PHPWord $PHPWord) public static function getDocument(PHPWord $PHPWord)
{ {
@ -29,7 +29,7 @@ class TestHelperDOCX
$zip->close(); $zip->close();
} }
return new Xml_Document(sys_get_temp_dir() . '/PHPWord_Unit_Test/'); return new XmlDocument(sys_get_temp_dir() . '/PHPWord_Unit_Test/');
} }
public static function clear() public static function clear()
@ -50,9 +50,9 @@ class TestHelperDOCX
foreach (scandir($dir) as $file) { foreach (scandir($dir) as $file) {
if ($file === '.' || $file === '..') { if ($file === '.' || $file === '..') {
continue; continue;
} else if (is_file($dir . "/" . $file)) { } elseif (is_file($dir . "/" . $file)) {
unlink($dir . "/" . $file); unlink($dir . "/" . $file);
} else if (is_dir($dir . "/" . $file)) { } elseif (is_dir($dir . "/" . $file)) {
self::deleteDir($dir . "/" . $file); self::deleteDir($dir . "/" . $file);
} }
} }
@ -60,65 +60,3 @@ class TestHelperDOCX
rmdir($dir); rmdir($dir);
} }
} }
class Xml_Document
{
/** @var string $path */
private $path;
/** @var \DOMDocument $dom */
private $dom;
/** @var \DOMXpath $xpath */
private $xpath;
/** @var string $file */
private $file;
/**
* @param string $path
*/
public function __construct($path)
{
$this->path = realpath($path);
}
/**
* @param string $file
* @return \DOMDocument
*/
public function getFileDom($file = 'word/document.xml')
{
if (null !== $this->dom && $file === $this->file) {
return $this->dom;
}
$this->xpath = null;
$this->file = $file;
$file = $this->path . '/' . $file;
$this->dom = new DOMDocument();
$this->dom->load($file);
return $this->dom;
}
/**
* @param string $path
* @param string $file
* @return \DOMElement
*/
public function getElement($path, $file = 'word/document.xml')
{
if ($this->dom === null || $file !== $this->file) {
$this->getFileDom($file);
}
if (null === $this->xpath) {
$this->xpath = new \DOMXpath($this->dom);
}
$elements = $this->xpath->query($path);
return $elements->item(0);
}
}

View File

@ -0,0 +1,66 @@
<?php
namespace PHPWord\Tests;
use DOMDocument;
class XmlDocument
{
/** @var string $path */
private $path;
/** @var \DOMDocument $dom */
private $dom;
/** @var \DOMXpath $xpath */
private $xpath;
/** @var string $file */
private $file;
/**
* @param string $path
*/
public function __construct($path)
{
$this->path = realpath($path);
}
/**
* @param string $file
* @return \DOMDocument
*/
public function getFileDom($file = 'word/document.xml')
{
if (null !== $this->dom && $file === $this->file) {
return $this->dom;
}
$this->xpath = null;
$this->file = $file;
$file = $this->path . '/' . $file;
$this->dom = new DOMDocument();
$this->dom->load($file);
return $this->dom;
}
/**
* @param string $path
* @param string $file
* @return \DOMElement
*/
public function getElement($path, $file = 'word/document.xml')
{
if ($this->dom === null || $file !== $this->file) {
$this->getFileDom($file);
}
if (null === $this->xpath) {
$this->xpath = new \DOMXpath($this->dom);
}
$elements = $this->xpath->query($path);
return $elements->item(0);
}
}

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