This commit is contained in:
jhfangying 2014-03-13 15:50:56 +08:00
commit b79a66ba9e
107 changed files with 2433 additions and 715 deletions

View File

@ -26,12 +26,13 @@
*/
/** PHPWORD_BASE_PATH */
// @codeCoverageIgnoreStart
if (!defined('PHPWORD_BASE_PATH')) {
define('PHPWORD_BASE_PATH', dirname(__FILE__) . '/');
require PHPWORD_BASE_PATH . 'PHPWord/Autoloader.php';
PHPWord_Autoloader::Register();
}
// @codeCoverageIgnoreEnd
/**
* PHPWord
@ -155,7 +156,7 @@ class PHPWord
}
/**
* Get default Font size
* Get default Font size (in points)
* @return string
*/
public function getDefaultFontSize()
@ -164,15 +165,24 @@ class PHPWord
}
/**
* Set default Font size
* Set default Font size (in points)
* @param int $pValue
*/
public function setDefaultFontSize($pValue)
{
$pValue = $pValue * 2;
$this->_defaultFontSize = $pValue;
}
/**
* Set default paragraph style definition to styles.xml
*
* @param array $styles Paragraph style definition
*/
public function setDefaultParagraphStyle($styles)
{
PHPWord_Style::setDefaultParagraphStyle($styles);
}
/**
* Adds a paragraph style definition to styles.xml
*
@ -217,16 +227,6 @@ class PHPWord
PHPWord_Style::addTitleStyle($titleCount, $styleFont, $styleParagraph);
}
/**
* Set default paragraph style definition to styles.xml
*
* @param array $styles Paragraph style definition
*/
public function setDefaultParagraphStyle($styles)
{
PHPWord_Style::setDefaultParagraphStyle($styles);
}
/**
* Adds a hyperlink style to styles.xml
*
@ -247,15 +247,6 @@ class PHPWord
return $this->_sectionCollection;
}
/**
* Get section count
* @return int
*/
private function _countSections()
{
return count($this->_sectionCollection);
}
/**
* Load a Template File
*
@ -268,7 +259,18 @@ class PHPWord
$template = new PHPWord_Template($strFilename);
return $template;
} else {
trigger_error('Template file ' . $strFilename . ' not found.', E_USER_ERROR);
throw new PHPWord_Exception(
"Template file {$strFilename} not found."
);
}
}
/**
* Get section count
* @return int
*/
private function _countSections()
{
return count($this->_sectionCollection);
}
}

View File

@ -30,6 +30,13 @@
*/
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
@ -101,6 +108,20 @@ class PHPWord_DocumentProperties
*/
private $_company;
/**
* Manager
*
* @var string
*/
private $_manager;
/**
* Custom Properties
*
* @var string
*/
private $_customProperties = array();
/**
* Create new PHPWord_DocumentProperties
*/
@ -116,6 +137,7 @@ class PHPWord_DocumentProperties
$this->_keywords = '';
$this->_category = '';
$this->_company = '';
$this->_manager = '';
}
/**
@ -343,4 +365,243 @@ class PHPWord_DocumentProperties
$this->_company = $pValue;
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

@ -2,7 +2,7 @@
/**
* PHPWord
*
* Copyright (c) 2011 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
@ -20,20 +20,17 @@
*
* @category 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
* @version Beta 0.6.3, 08.07.2011
* @version 0.7.0
*/
/**
* PHPWord_Footnote
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2011 PHPWord
*/
class PHPWord_Footnote {
class PHPWord_Footnote
{
/**
* Footnote Elements
@ -57,7 +54,8 @@ class PHPWord_Footnote {
*
* @return mixed
*/
public static function addFootnoteElement(PHPWord_Section_Footnote $footnote) {
public static function addFootnoteElement(PHPWord_Section_Footnote $footnote)
{
$refID = self::countFootnoteElements() + 2;
self::$_footnoteCollection[] = $footnote;
@ -70,7 +68,8 @@ class PHPWord_Footnote {
*
* @return array
*/
public static function getFootnoteElements() {
public static function getFootnoteElements()
{
return self::$_footnoteCollection;
}
@ -79,7 +78,8 @@ class PHPWord_Footnote {
*
* @return int
*/
public static function countFootnoteElements() {
public static function countFootnoteElements()
{
return count(self::$_footnoteCollection);
}
@ -91,7 +91,8 @@ class PHPWord_Footnote {
*
* @return mixed
*/
public static function addFootnoteLinkElement($linkSrc) {
public static function addFootnoteLinkElement($linkSrc)
{
$rID = self::countFootnoteLinkElements() + 1;
$link = array();
@ -109,7 +110,8 @@ class PHPWord_Footnote {
*
* @return array
*/
public static function getFootnoteLinkElements() {
public static function getFootnoteLinkElements()
{
return self::$_footnoteLink;
}
@ -118,8 +120,8 @@ class PHPWord_Footnote {
*
* @return int
*/
public static function countFootnoteLinkElements() {
public static function countFootnoteLinkElements()
{
return count(self::$_footnoteLink);
}
}

View File

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

View File

@ -37,7 +37,8 @@ class PHPWord_IOFactory
* @var 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");
}
/**
* 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

@ -30,15 +30,16 @@
*/
class PHPWord_Media
{
/**
* Section Media Elements
*
* @var array
*/
private static $_sectionMedia = array('images' => array(),
private static $_sectionMedia = array(
'images' => array(),
'embeddings' => array(),
'links' => array());
'links' => array()
);
/**
* Header Media Elements
@ -61,18 +62,18 @@ class PHPWord_Media
*/
private static $_objectId = 1325353440;
/**
* Add new Section Media Element
*
* @param string $src
* @param string $type
* @param PHPWord_Section_MemoryImage|null $memoryImage
* @return mixed
*/
public static function addSectionMediaElement($src, $type, PHPWord_Section_MemoryImage $memoryImage = null)
{
$mediaId = md5($src);
$key = ($type == 'image') ? 'images' : 'embeddings';
$key = ($type === 'image') ? 'images' : 'embeddings';
if (!array_key_exists($mediaId, self::$_sectionMedia[$key])) {
$cImg = self::countSectionMediaElements('images');
@ -81,26 +82,39 @@ class PHPWord_Media
$media = array();
if ($type == 'image') {
$folder = null;
$file = null;
if ($type === 'image') {
$cImg++;
$inf = pathinfo($src);
$isMemImage = (substr(strtolower($inf['extension']), 0, 3) == 'php' && $type == 'image') ? true : false;
$isMemImage = false;
if (stripos(strrev($src), strrev('.php')) === 0) {
$isMemImage = true;
}
$extension = '';
if ($isMemImage) {
$ext = $memoryImage->getImageExtension();
$extension = $memoryImage->getImageExtension();
$media['isMemImage'] = true;
$media['createfunction'] = $memoryImage->getImageCreateFunction();
$media['imagefunction'] = $memoryImage->getImageFunction();
} else {
$ext = $inf['extension'];
if ($ext == 'jpeg') { // Office crashes when adding a jpEg Image, so rename to jpg
$ext = 'jpg';
$imageType = exif_imagetype($src);
if ($imageType === IMAGETYPE_JPEG) {
$extension = 'jpg';
} elseif ($imageType === IMAGETYPE_GIF) {
$extension = 'gif';
} elseif ($imageType === IMAGETYPE_PNG) {
$extension = 'png';
} elseif ($imageType === IMAGETYPE_BMP) {
$extension = 'bmp';
} elseif ($imageType === IMAGETYPE_TIFF_II || $imageType === IMAGETYPE_TIFF_MM) {
$extension = 'tif';
}
}
$folder = 'media';
$file = $type . $cImg . '.' . strtolower($ext);
} elseif ($type == 'oleObject') {
$file = $type . $cImg . '.' . strtolower($extension);
} elseif ($type === 'oleObject') {
$cObj++;
$folder = 'embedding';
$file = $type . $cObj . '.bin';
@ -113,27 +127,24 @@ class PHPWord_Media
self::$_sectionMedia[$key][$mediaId] = $media;
if ($type == 'oleObject') {
if ($type === 'oleObject') {
return array($rID, ++self::$_objectId);
} else {
}
return $rID;
}
} else {
if ($type == 'oleObject') {
if ($type === 'oleObject') {
$rID = self::$_sectionMedia[$key][$mediaId]['rID'];
return array($rID, ++self::$_objectId);
} else {
}
return self::$_sectionMedia[$key][$mediaId]['rID'];
}
}
}
/**
* Add new Section Link Element
*
* @param string $linkSrc
* @param string $linkName
*
* @return mixed
*/
public static function addSectionLinkElement($linkSrc)
@ -160,13 +171,13 @@ class PHPWord_Media
{
if (!is_null($key)) {
return self::$_sectionMedia[$key];
} else {
}
$arrImages = self::$_sectionMedia['images'];
$arrObjects = self::$_sectionMedia['embeddings'];
$arrLinks = self::$_sectionMedia['links'];
return array_merge($arrImages, $arrObjects, $arrLinks);
}
}
/**
* Get Section Media Elements Count
@ -178,19 +189,20 @@ class PHPWord_Media
{
if (!is_null($key)) {
return count(self::$_sectionMedia[$key]);
} else {
}
$cImages = count(self::$_sectionMedia['images']);
$cObjects = count(self::$_sectionMedia['embeddings']);
$cLinks = count(self::$_sectionMedia['links']);
return ($cImages + $cObjects + $cLinks);
}
}
/**
* Add new Header Media Element
*
* @param int $headerCount
* @param string $src
* @param PHPWord_Section_MemoryImage|null $memoryImage
* @return int
*/
public static function addHeaderMediaElement($headerCount, $src, PHPWord_Section_MemoryImage $memoryImage = null)
@ -232,9 +244,8 @@ class PHPWord_Media
self::$_headerMedia[$key][$mediaId] = $media;
return $rID;
} else {
return self::$_headerMedia[$key][$mediaId]['rID'];
}
return self::$_headerMedia[$key][$mediaId]['rID'];
}
/**
@ -263,6 +274,7 @@ class PHPWord_Media
*
* @param int $footerCount
* @param string $src
* @param PHPWord_Section_MemoryImage|null $memoryImage
* @return int
*/
public static function addFooterMediaElement($footerCount, $src, PHPWord_Section_MemoryImage $memoryImage = null)
@ -304,9 +316,8 @@ class PHPWord_Media
self::$_footerMedia[$key][$mediaId] = $media;
return $rID;
} else {
return self::$_footerMedia[$key][$mediaId]['rID'];
}
return self::$_footerMedia[$key][$mediaId]['rID'];
}
/**
@ -330,4 +341,3 @@ class PHPWord_Media
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->_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)) {
foreach ($settings as $key => $value) {
if (substr($key, 0, 1) != '_') {
@ -416,7 +425,8 @@ class PHPWord_Section
* @param string $text
* @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->setReferenceId($refID);

View File

@ -2,7 +2,7 @@
/**
* PHPWord
*
* Copyright (c) 2011 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
@ -20,20 +20,16 @@
*
* @category 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
* @version Beta 0.6.3, 08.07.2011
* @version 0.7.0
*/
/**
* PHPWord_Section_Footnote
*
* @category PHPWord
* @package PHPWord_Section
* @copyright Copyright (c) 2011 PHPWord
*/
class PHPWord_Section_Footnote {
class PHPWord_Section_Footnote
{
/**
* Paragraph style
@ -59,16 +55,17 @@ class PHPWord_Section_Footnote {
/**
* Create a new Footnote Element
*/
public function __construct($styleParagraph = null) {
public function __construct($styleParagraph = null)
{
$this->_elementCollection = array();
// Set paragraph style
if(is_array($styleParagraph)) {
if (is_array($styleParagraph)) {
$this->_styleParagraph = new PHPWord_Style_Paragraph();
foreach($styleParagraph as $key => $value) {
if(substr($key, 0, 1) != '_') {
$key = '_'.$key;
foreach ($styleParagraph as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_styleParagraph->setStyleValue($key, $value);
}
@ -85,7 +82,8 @@ class PHPWord_Section_Footnote {
* @var mixed $styleFont
* @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);
$this->_elementCollection[] = $text;
@ -100,7 +98,8 @@ class PHPWord_Section_Footnote {
* @param mixed $styleFont
* @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);
$rID = PHPWord_Footnote::addFootnoteLinkElement($linkSrc);
@ -115,7 +114,8 @@ class PHPWord_Section_Footnote {
*
* @return array
*/
public function getElements() {
public function getElements()
{
return $this->_elementCollection;
}
@ -124,7 +124,8 @@ class PHPWord_Section_Footnote {
*
* @return PHPWord_Style_Paragraph
*/
public function getParagraphStyle() {
public function getParagraphStyle()
{
return $this->_styleParagraph;
}
@ -133,7 +134,8 @@ class PHPWord_Section_Footnote {
*
* @return int
*/
public function getReferenceId() {
public function getReferenceId()
{
return $this->_refId;
}
@ -142,7 +144,8 @@ class PHPWord_Section_Footnote {
*
* @param int $refId
*/
public function setReferenceId($refId) {
public function setReferenceId($refId)
{
$this->_refId = $refId;
}
}

View File

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

View File

@ -30,7 +30,6 @@
*/
class PHPWord_Section_MemoryImage
{
/**
* Image Src
*
@ -85,7 +84,7 @@ class PHPWord_Section_MemoryImage
* Create a new Image
*
* @param string $src
* @param mixed style
* @param mixed $style
*/
public function __construct($src, $style = null)
{
@ -113,10 +112,6 @@ class PHPWord_Section_MemoryImage
}
$this->_setFunctions();
return $this;
} else {
return false;
}
}
@ -145,7 +140,6 @@ class PHPWord_Section_MemoryImage
}
}
/**
* Get Image style
*

View File

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

View File

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

View File

@ -116,7 +116,8 @@ class PHPWord_Section_TextRun
* @param mixed $styleFont
* @return PHPWord_Section_Image
*/
public function addImage($imageSrc, $style = null) {
public function addImage($imageSrc, $style = null)
{
$image = new PHPWord_Section_Image($imageSrc, $style);
if (!is_null($image->getSource())) {
@ -130,13 +131,26 @@ class PHPWord_Section_TextRun
}
}
/**
* Add a Text Break
*
* @param int $count
*/
public function addTextBreak($count = 1)
{
for ($i=1; $i<=$count; $i++) {
$this->_elementCollection[] = new PHPWord_Section_TextBreak();
}
}
/**
* Create a new Footnote Element
*
* @param string $text
* @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->setReferenceId($refID);

View File

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

View File

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

View File

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

View File

@ -121,7 +121,7 @@ class PHPWord_Shared_ZipStreamWrapper
/**
* Read stream
*/
function stream_read($count)
public function stream_read($count)
{
$ret = substr($this->_data, $this->_position, $count);
$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
*/
private $_gridSpan = NULL;
private $_gridSpan = null;
/**
* rowspan (restart, continue)
@ -133,7 +133,7 @@ class PHPWord_Style_Cell
*
* @var string
*/
private $_vMerge = NULL;
private $_vMerge = null;
/**
* Create a new Cell Style

View File

@ -81,5 +81,4 @@ class PHPWord_Style_Row
{
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 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
$this->_val = (self::isStopType($val)) ? $val : 'clear';
@ -101,7 +101,7 @@ class PHPWord_Style_Tab
$this->_position = (is_numeric($position)) ? intval($position) : 0;
// 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
*/
public function toXml(PHPWord_Shared_XMLWriter &$objWriter = NULL)
public function toXml(PHPWord_Shared_XMLWriter &$objWriter = null)
{
if (isset($objWriter)) {
$objWriter->startElement("w:tab");

View File

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

View File

@ -133,7 +133,7 @@ class PHPWord_Template
}
$replace = htmlspecialchars($replace);
} else {
foreach($replace as $key=>$value) {
foreach ($replace as $key => $value) {
$replace[$key] = htmlspecialchars($value);
}
}
@ -157,7 +157,8 @@ class PHPWord_Template
*
* @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));
@ -174,7 +175,8 @@ class PHPWord_Template
*
* @param mixed $offset
*/
private function _findRowEnd($offset) {
private function _findRowEnd($offset)
{
$rowEnd = strpos($this->_documentXML, "</w:tr>", $offset) + 7;
return $rowEnd;
}
@ -184,7 +186,8 @@ class PHPWord_Template
*
* @param mixed $offset
*/
private function _getSlice($startPosition, $endPosition = 0) {
private function _getSlice($startPosition, $endPosition = 0)
{
if (!$endPosition) {
$endPosition = strlen($this->_documentXML);
}
@ -197,8 +200,9 @@ class PHPWord_Template
* @param mixed $search
* @param mixed $numberOfClones
*/
public function cloneRow($search, $numberOfClones) {
if(substr($search, 0, 2) !== '${' && substr($search, -1) !== '}') {
public function cloneRow($search, $numberOfClones)
{
if (substr($search, 0, 2) !== '${' && substr($search, -1) !== '}') {
$search = '${'.$search.'}';
}
@ -216,7 +220,7 @@ class PHPWord_Template
if (preg_match('#<w:vMerge w:val="restart"/>#', $xmlRow)) {
$extraRowStart = $rowEnd;
$extraRowEnd = $rowEnd;
while(true) {
while (true) {
$extraRowStart = $this->_findRowStart($extraRowEnd + 1);
$extraRowEnd = $this->_findRowEnd($extraRowEnd + 1);
@ -238,7 +242,7 @@ class PHPWord_Template
$result = $this->_getSlice(0, $rowStart);
for ($i = 1; $i <= $numberOfClones; $i++) {
$result .= preg_replace('/\$\{(.*?)\}/','\${\\1#'.$i.'}', $xmlRow);
$result .= preg_replace('/\$\{(.*?)\}/', '\${\\1#'.$i.'}', $xmlRow);
}
$result .= $this->_getSlice($rowEnd);
@ -250,7 +254,8 @@ class PHPWord_Template
*
* @return string
*/
public function save() {
public function save()
{
$this->_objZip->addFromString('word/document.xml', $this->_documentXML);
// Close zip file
@ -266,7 +271,8 @@ class PHPWord_Template
*
* @param string $strFilename
*/
public function saveAs($strFilename) {
public function saveAs($strFilename)
{
$tempFilename = $this->save();
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);
} else if ($this->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_MemoryDrawing) {
} elseif ($this->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_MemoryDrawing) {
ob_start();
call_user_func(
$this->getDrawingHashTable()->getByIndex($i)->getRenderingFunction(),
@ -236,7 +236,7 @@ class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter
* @param string $pPartName Writer part name
* @return PHPWord_Writer_ODText_WriterPart
*/
function getWriterPart($pPartName = '')
public function getWriterPart($pPartName = '')
{
if ($pPartName != '' && isset($this->_writerParts[strtolower($pPartName)])) {
return $this->_writerParts[strtolower($pPartName)];

View File

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

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:full-path', 'Pictures/' . str_replace(' ', '_', $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()));
$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 = explode('/', $extension);
$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';
}
}

View File

@ -182,8 +182,8 @@ class PHPWord_Writer_ODText_Styles extends PHPWord_Writer_ODText_WriterPart
}
$objWriter->endElement();
$objWriter->endElement();
} // PHPWord_Style_Paragraph
elseif ($style instanceof PHPWord_Style_Paragraph) {
} elseif ($style instanceof PHPWord_Style_Paragraph) {
// PHPWord_Style_Paragraph
// style:style
$objWriter->startElement('style:style');
$objWriter->writeAttribute('style:name', $styleName);
@ -197,9 +197,8 @@ class PHPWord_Writer_ODText_Styles extends PHPWord_Writer_ODText_WriterPart
$objWriter->endElement();
$objWriter->endElement();
} // PHPWord_Style_TableFull
elseif ($style instanceof PHPWord_Style_TableFull) {
} elseif ($style instanceof PHPWord_Style_TableFull) {
// 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");
fwrite($hFile, $this->_getData());
fwrite($hFile, $this->getData());
fclose($hFile);
// 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;
}
private function _getData()
private function getData()
{
// PHPWord object : $this->_document
$this->_fontTable = $this->_getDataFont();
$this->_colorTable = $this->_getDataColor();
$this->_fontTable = $this->getDataFont();
$this->_colorTable = $this->getDataColor();
$sRTFContent = '{\rtf1';
// 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 .= PHP_EOL;
// Body
$sRTFContent .= $this->_getDataContent();
$sRTFContent .= $this->getDataContent();
$sRTFContent .= '}';
@ -188,7 +188,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
return $sRTFContent;
}
private function _getDataFont()
private function getDataFont()
{
$pPHPWord = $this->_document;
@ -204,7 +204,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
foreach ($styles as $styleName => $style) {
// 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();
}
}
@ -226,7 +226,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
$fStyle = $element->getFontStyle();
if ($fStyle instanceof PHPWord_Style_Font) {
if (in_array($fStyle->getName(), $arrFonts) == FALSE) {
if (in_array($fStyle->getName(), $arrFonts) == false) {
$arrFonts[] = $fStyle->getName();
}
}
@ -238,7 +238,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
return $arrFonts;
}
private function _getDataColor()
private function getDataColor()
{
$pPHPWord = $this->_document;
@ -254,10 +254,10 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
if ($style instanceof PHPWord_Style_Font) {
$color = $style->getColor();
$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;
}
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;
}
}
@ -279,10 +279,10 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
$fStyle = $element->getFontStyle();
if ($fStyle instanceof PHPWord_Style_Font) {
if (in_array($fStyle->getColor(), $arrColors) == FALSE) {
if (in_array($fStyle->getColor(), $arrColors) == false) {
$arrColors[] = $fStyle->getColor();
}
if (in_array($fStyle->getFgColor(), $arrColors) == FALSE) {
if (in_array($fStyle->getFgColor(), $arrColors) == false) {
$arrColors[] = $fStyle->getFgColor();
}
}
@ -294,7 +294,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
return $arrColors;
}
private function _getDataContent()
private function getDataContent()
{
$pPHPWord = $this->_document;
$sRTFBody = '';
@ -309,11 +309,11 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
$_elements = $section->getElements();
foreach ($_elements as $element) {
if ($element instanceof PHPWord_Section_Text) {
$sRTFBody .= $this->_getDataContent_writeText($element);
$sRTFBody .= $this->getDataContentText($element);
} elseif ($element instanceof PHPWord_Section_TextBreak) {
$sRTFBody .= $this->_getDataContent_writeTextBreak();
$sRTFBody .= $this->getDataContentTextBreak();
} elseif ($element instanceof PHPWord_Section_TextRun) {
$sRTFBody .= $this->_getDataContent_writeTextRun($element);
$sRTFBody .= $this->getDataContentTextRun($element);
/*
} elseif($element instanceof PHPWord_Section_Link) {
$this->_writeLink($objWriter, $element);
@ -346,7 +346,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
/**
* Get text
*/
private function _getDataContent_writeText(PHPWord_Section_Text $text, $withoutP = false)
private function getDataContentText(PHPWord_Section_Text $text, $withoutP = false)
{
$sRTFText = '';
@ -384,7 +384,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
if ($styleFont) {
if ($styleFont->getColor() != null) {
$idxColor = array_search($styleFont->getColor(), $this->_colorTable);
if ($idxColor !== FALSE) {
if ($idxColor !== false) {
$sRTFText .= '\cf' . ($idxColor + 1);
}
} else {
@ -392,7 +392,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
}
if ($styleFont->getName() != null) {
$idxFont = array_search($styleFont->getName(), $this->_fontTable);
if ($idxFont !== FALSE) {
if ($idxFont !== false) {
$sRTFText .= '\f' . $idxFont;
}
} else {
@ -437,7 +437,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
/**
* Get text run content
*/
private function _getDataContent_writeTextRun(PHPWord_Section_TextRun $textrun)
private function getDataContentTextRun(PHPWord_Section_TextRun $textrun)
{
$sRTFText = '';
$elements = $textrun->getElements();
@ -446,7 +446,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
foreach ($elements as $element) {
if ($element instanceof PHPWord_Section_Text) {
$sRTFText .= '{';
$sRTFText .= $this->_getDataContent_writeText($element, true);
$sRTFText .= $this->getDataContentText($element, true);
$sRTFText .= '}' . PHP_EOL;
}
}
@ -455,12 +455,10 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
return $sRTFText;
}
private function _getDataContent_writeTextBreak()
private function getDataContentTextBreak()
{
$this->_lastParagraphStyle = '';
return '\par' . PHP_EOL;
}
}

View File

@ -25,6 +25,9 @@
* @version 0.7.0
*/
use PhpOffice\PhpWord\Exceptions\InvalidImageException;
use PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException;
/**
* Class PHPWord_Writer_Word2007
*/
@ -115,7 +118,8 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter
$footnoteLinks = array();
$_footnoteElements = PHPWord_Footnote::getFootnoteLinkElements();
foreach($_footnoteElements as $element) { // loop through footnote link elements
// loop through footnote link elements
foreach ($_footnoteElements as $element) {
$footnoteLinks[] = $element;
}
@ -190,24 +194,38 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter
}
}
private function _chkContentTypes($src)
/**
* @param string $src
*/
private function checkContentTypes($src)
{
$srcInfo = pathinfo($src);
$extension = strtolower($srcInfo['extension']);
if (substr($extension, 0, 3) == 'php') {
$extension = null;
if (stripos(strrev($src), strrev('.php')) === 0) {
$extension = 'php';
} else {
$imageType = exif_imagetype($src);
if ($imageType === IMAGETYPE_JPEG) {
$extension = 'jpg';
} elseif ($imageType === IMAGETYPE_GIF) {
$extension = 'gif';
} elseif ($imageType === IMAGETYPE_PNG) {
$extension = 'png';
} elseif ($imageType === IMAGETYPE_BMP) {
$extension = 'bmp';
} elseif ($imageType === IMAGETYPE_TIFF_II || $imageType === IMAGETYPE_TIFF_MM) {
$extension = 'tif';
}
}
$_supportedImageTypes = array('jpg', 'jpeg', 'gif', 'png', 'bmp', 'tif', 'tiff', 'php');
if (in_array($extension, $_supportedImageTypes)) {
$imagedata = getimagesize($src);
$imagetype = image_type_to_mime_type($imagedata[2]);
$imageext = image_type_to_extension($imagedata[2]);
$imageext = str_replace('.', '', $imageext);
if ($imageext == 'jpeg') $imageext = 'jpg';
if (!in_array($imagetype, $this->_imageTypes)) {
$this->_imageTypes[$imageext] = $imagetype;
if (isset($extension)) {
$imageData = getimagesize($src);
$imageType = image_type_to_mime_type($imageData[2]);
$imageExtension = str_replace('.', '', image_type_to_extension($imageData[2]));
if ($imageExtension === 'jpeg') {
$imageExtension = 'jpg';
}
if (!in_array($imageType, $this->_imageTypes)) {
$this->_imageTypes[$imageExtension] = $imageType;
}
} else {
if (!in_array($extension, $this->_objectTypes)) {
@ -256,10 +274,10 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter
$objZip->addFromString('word/' . $element['target'], $imageContents);
imagedestroy($image);
$this->_chkContentTypes($element['source']);
$this->checkContentTypes($element['source']);
} else {
$objZip->addFile($element['source'], 'word/' . $element['target']);
$this->_chkContentTypes($element['source']);
$this->checkContentTypes($element['source']);
}
}
}

18
Classes/PHPWord/Writer/Word2007/Base.php Executable file → Normal file
View File

@ -108,6 +108,8 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart {
$this->_writeImage($objWriter, $element, true);
} elseif ($element instanceof PHPWord_Section_Footnote) {
$this->_writeFootnoteReference($objWriter, $element, true);
} elseif ($element instanceof PHPWord_Section_TextBreak) {
$objWriter->writeElement('w:br');
}
}
}
@ -124,7 +126,14 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart {
* @return void
*/
protected function _writeParagraphStyle(
<<<<<<< HEAD
PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_Paragraph $style, $withoutPPR = false) {
=======
PHPWord_Shared_XMLWriter $objWriter = null,
PHPWord_Style_Paragraph $style,
$withoutPPR = false
) {
>>>>>>> 5e0fc7a2d815c96de6f6cdd081404df61e8ed886
$align = $style->getAlign();
$spacing = $style->getSpacing();
$spaceBefore = $style->getSpaceBefore();
@ -870,7 +879,8 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart {
$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->writeAttribute('w:id', $footnote->getReferenceId());
@ -904,7 +914,8 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart {
$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) {
$objWriter->startElement('w:p');
}
@ -921,5 +932,8 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart {
$objWriter->endElement(); // w:p
}
}
<<<<<<< HEAD
=======
>>>>>>> 5e0fc7a2d815c96de6f6cdd081404df61e8ed886
}

View File

@ -50,12 +50,16 @@ class PHPWord_Writer_Word2007_ContentTypes extends PHPWord_Writer_Word2007_Write
// Rels
$this->_writeDefaultContentType(
$objWriter, 'rels', 'application/vnd.openxmlformats-package.relationships+xml'
$objWriter,
'rels',
'application/vnd.openxmlformats-package.relationships+xml'
);
// XML
$this->_writeDefaultContentType(
$objWriter, 'xml', 'application/xml'
$objWriter,
'xml',
'application/xml'
);
// Add media content-types
@ -65,62 +69,88 @@ class PHPWord_Writer_Word2007_ContentTypes extends PHPWord_Writer_Word2007_Write
// Add embedding content-types
if (count($_objectTypes) > 0) {
$this->_writeDefaultContentType($objWriter, 'bin', 'application/vnd.openxmlformats-officedocument.oleObject');
$this->_writeDefaultContentType(
$objWriter,
'bin',
'application/vnd.openxmlformats-officedocument.oleObject'
);
}
// DocProps
$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(
$objWriter, '/docProps/core.xml', 'application/vnd.openxmlformats-package.core-properties+xml'
$objWriter,
'/docProps/core.xml',
'application/vnd.openxmlformats-package.core-properties+xml'
);
// Document
$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
$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
$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
$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
$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
$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
$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++) {
$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++) {
$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);
} elseif ($element instanceof PHPWord_TOC) {
$this->_writeTOC($objWriter);
} elseif($element instanceof PHPWord_Section_Footnote) {
} elseif ($element instanceof PHPWord_Section_Footnote) {
$this->_writeFootnoteReference($objWriter, $element);
}
}

View File

@ -26,8 +26,10 @@
*/
class PHPWord_Writer_Word2007_Footnotes extends PHPWord_Writer_Word2007_Base {
public function writeFootnotes($allFootnotesCollection) {
class PHPWord_Writer_Word2007_Footnotes extends PHPWord_Writer_Word2007_Base
{
public function writeFootnotes($allFootnotesCollection)
{
// Create XML writer
$objWriter = null;
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->startElement('w:footnotes');
$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:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$objWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
// write separator and continuation separator
$objWriter->startElement('w:footnote');
@ -67,8 +69,8 @@ class PHPWord_Writer_Word2007_Footnotes extends PHPWord_Writer_Word2007_Base {
$objWriter->endElement(); // w:footnote
foreach($allFootnotesCollection as $footnote) {
if($footnote instanceof PHPWord_Section_Footnote) {
foreach ($allFootnotesCollection as $footnote) {
if ($footnote instanceof PHPWord_Section_Footnote) {
$this->_writeFootnote($objWriter, $footnote);
}
}

View File

@ -26,8 +26,10 @@
*/
class PHPWord_Writer_Word2007_FootnotesRels extends PHPWord_Writer_Word2007_WriterPart {
public function writeFootnotesRels($_relsCollection) {
class PHPWord_Writer_Word2007_FootnotesRels extends PHPWord_Writer_Word2007_WriterPart
{
public function writeFootnotesRels($_relsCollection)
{
// Create XML writer
$objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
@ -37,26 +39,20 @@ class PHPWord_Writer_Word2007_FootnotesRels extends PHPWord_Writer_Word2007_Writ
}
// XML header
$objWriter->startDocument('1.0','UTF-8','yes');
$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) {
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
);
$this->_writeRelationship($objWriter, $relationId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType, $relationName, $targetMode);
}
$objWriter->endElement();
@ -65,9 +61,10 @@ class PHPWord_Writer_Word2007_FootnotesRels extends PHPWord_Writer_Word2007_Writ
return $objWriter->getData();
}
private function _writeRelationship(PHPWord_Shared_XMLWriter $objWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '') {
if($pType != '' && $pTarget != '') {
if(strpos($pId, 'rId') === false) {
private function _writeRelationship(PHPWord_Shared_XMLWriter $objWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '')
{
if ($pType != '' && $pTarget != '') {
if (strpos($pId, 'rId') === false) {
$pId = 'rId' . $pId;
}
@ -77,7 +74,7 @@ class PHPWord_Writer_Word2007_FootnotesRels extends PHPWord_Writer_Word2007_Writ
$objWriter->writeAttribute('Type', $pType);
$objWriter->writeAttribute('Target', $pTarget);
if($pTargetMode != '') {
if ($pTargetMode != '') {
$objWriter->writeAttribute('TargetMode', $pTargetMode);
}

View File

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

View File

@ -16,8 +16,14 @@ class AutoloaderTest extends PHPUnit_Framework_TestCase
public function testAutoloadLegacy()
{
$this->assertNull(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');
$this->assertNull(
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()
@ -25,8 +31,20 @@ class AutoloaderTest extends PHPUnit_Framework_TestCase
$declared = get_declared_classes();
$declaredCount = count($declared);
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');
Autoloader::autoload('PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException'); // TODO change this class to the main PHPWord class when it is namespaced
$this->assertTrue(in_array('PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException', get_declared_classes()), 'PhpOffice\\PhpWord\\Autoloader::autoload() failed to autoload the PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException class');
$this->assertEquals(
$declaredCount,
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()
{
$this->assertAttributeEquals(PHPWord_IOFactory::getSearchLocations(), '_searchLocations', 'PHPWord_IOFactory');
$this->assertAttributeEquals(
PHPWord_IOFactory::getSearchLocations(),
'_searchLocations',
'PHPWord_IOFactory'
);
}
public function testSetSearchLocationsWithArray()
@ -38,7 +42,11 @@ class IOFactoryTest extends \PHPUnit_Framework_TestCase
{
PHPWord_IOFactory::setSearchLocations(array());
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();
$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

@ -3,6 +3,7 @@ namespace PHPWord\Tests;
use PHPUnit_Framework_TestCase;
use PHPWord_Media;
use PHPWord_Section;
class MediaTest extends \PHPUnit_Framework_TestCase
{
@ -25,4 +26,26 @@ class MediaTest extends \PHPUnit_Framework_TestCase
{
$this->assertAttributeEquals(PHPWord_Media::getFooterMediaElements(), '_footerMedia', 'PHPWord_Media');
}
/**
* Todo: add memory image to this test
*
* @covers PHPWord_Media::addSectionMediaElement
*/
public function testAddSectionMediaElement()
{
$section = new PHPWord_Section(0);
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars_noext_jpg");
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars.jpg");
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mario.gif");
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/firefox.png");
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/duke_nukem.bmp");
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/angela_merkel.tif");
$elements = $section->getElements();
$this->assertEquals(6, count($elements));
foreach ($elements as $element) {
$this->assertInstanceOf('PHPWord_Section_Image', $element);
}
}
}

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,7 +26,11 @@ class PreserveTextTest extends \PHPUnit_Framework_TestCase
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_Paragraph', $oPreserveText->getParagraphStyle());
}

View File

@ -87,7 +87,9 @@ class FooterTest extends \PHPUnit_Framework_TestCase
public function testAddMemoryImage()
{
$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->assertInstanceOf('PHPWord_Section_MemoryImage', $element);

View File

@ -83,7 +83,9 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
public function testAddMemoryImage()
{
$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->assertInstanceOf('PHPWord_Section_MemoryImage', $element);

View File

@ -28,11 +28,18 @@ class ImageTest extends \PHPUnit_Framework_TestCase
\DIRECTORY_SEPARATOR,
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());
}
/**
* @covers PHPWord_Section_Image::__construct
*/
public function testValidImageTypes()
{
new PHPWord_Section_Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars_noext_jpg");
@ -45,6 +52,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
/**
* @expectedException \PhpOffice\PhpWord\Exceptions\InvalidImageException
* @covers PHPWord_Section_Image::__construct
*/
public function testImageNotFound()
{
@ -53,6 +61,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
/**
* @expectedException \PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException
* @covers PHPWord_Section_Image::__construct
*/
public function testInvalidImageTypes()
{

View File

@ -20,7 +20,12 @@ class LinkTest extends \PHPUnit_Framework_TestCase
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->assertEquals($oLink->getLinkSrc(), 'http://www.google.com');

View File

@ -16,7 +16,12 @@ class ListItemTest extends \PHPUnit_Framework_TestCase
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->assertEquals($oListItem->getStyle()->getListType(), PHPWord_Style_ListItem::TYPE_NUMBER);

View File

@ -130,7 +130,9 @@ class CellTest extends \PHPUnit_Framework_TestCase
public function testAddMemoryImageSection()
{
$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->assertInstanceOf('PHPWord_Section_MemoryImage', $element);
@ -139,7 +141,9 @@ class CellTest extends \PHPUnit_Framework_TestCase
public function testAddMemoryImageHeader()
{
$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->assertInstanceOf('PHPWord_Section_MemoryImage', $element);
@ -148,7 +152,9 @@ class CellTest extends \PHPUnit_Framework_TestCase
public function testAddMemoryImageFooter()
{
$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->assertInstanceOf('PHPWord_Section_MemoryImage', $element);

View File

@ -22,7 +22,12 @@ class RowTest extends \PHPUnit_Framework_TestCase
{
$iVal = 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->assertInstanceOf('PHPWord_Style_Row', $oRow->getStyle());

View File

@ -26,7 +26,11 @@ class TableTest extends \PHPUnit_Framework_TestCase
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());
}

View File

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

View File

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

View File

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

View File

@ -12,7 +12,6 @@ use PHPWord_Style_Cell;
*/
class CellTest extends \PHPUnit_Framework_TestCase
{
/**
* Test setting style with normal value
*/

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -12,7 +12,6 @@ use PHPWord_Style_Table;
*/
class TableTest extends \PHPUnit_Framework_TestCase
{
/**
* Test set style value
*/
@ -50,5 +49,4 @@ class TableTest extends \PHPUnit_Framework_TestCase
}
$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('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

@ -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();
}
public function testWriteImage_Position()
{
$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()
public function testWriteParagraphStyleAlign()
{
$PHPWord = new PHPWord();
$section = $PHPWord->createSection();
@ -55,34 +33,10 @@ class BaseTest extends \PHPUnit_Framework_TestCase
$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
*/
public function testWriteParagraphStyle_Pagination()
public function testWriteParagraphStylePagination()
{
// Create the doc
$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()
{
$PHPWord = new PHPWord();

View File

@ -22,7 +22,7 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
TestHelperDOCX::clear();
}
public function testWriteEndSection_PageNumbering()
public function testWriteEndSectionPageNumbering()
{
$PHPWord = new PHPWord();
$section = $PHPWord->createSection();

View File

@ -0,0 +1,88 @@
<?php
namespace PHPWord\Tests\Writer;
use PHPUnit_Framework_TestCase;
use PHPWord_Writer_Word2007;
use PHPWord;
use PHPWord\Tests\TestHelperDOCX;
/**
* Class Word2007Test
*
* @package PHPWord\Tests
* @runTestsInSeparateProcesses
*/
class Word2007Test extends \PHPUnit_Framework_TestCase
{
public function tearDown()
{
TestHelperDOCX::clear();
}
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()
);
}
}
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);
}
/**
* @covers PHPWord_Writer_Word2007::checkContentTypes
*/
public function testCheckContentTypes()
{
$phpWord = new PHPWord();
$section = $phpWord->createSection();
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars_noext_jpg");
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars.jpg");
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mario.gif");
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/firefox.png");
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/duke_nukem.bmp");
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/angela_merkel.tif");
$doc = TestHelperDOCX::getDocument($phpWord);
$mediaPath = $doc->getPath() . "/word/media";
$this->assertFileEquals(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars_noext_jpg", $mediaPath . "/section_image1.jpg");
$this->assertFileEquals(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars.jpg", $mediaPath . "/section_image2.jpg");
$this->assertFileEquals(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mario.gif", $mediaPath . "/section_image3.gif");
$this->assertFileEquals(PHPWORD_TESTS_DIR_ROOT . "/_files/images/firefox.png", $mediaPath . "/section_image4.png");
$this->assertFileEquals(PHPWORD_TESTS_DIR_ROOT . "/_files/images/duke_nukem.bmp", $mediaPath . "/section_image5.bmp");
$this->assertFileEquals(PHPWORD_TESTS_DIR_ROOT . "/_files/images/angela_merkel.tif", $mediaPath . "/section_image6.tif");
}
}

183
Tests/PHPWordTest.php Normal file
View File

@ -0,0 +1,183 @@
<?php
namespace PHPWord\Tests;
use PHPUnit_Framework_TestCase;
use PHPWord;
use PHPWord_DocumentProperties;
use PHPWord_Section;
use PHPWord_Style;
/**
* @covers PHPWord
*/
class PHPWordTest extends PHPUnit_Framework_TestCase
{
/**
* @var PHPWord
*/
protected $object;
/**
* @covers PHPWord::__construct
* @covers PHPWord::getProperties
* @covers PHPWord::getDefaultFontName
* @covers PHPWord::getDefaultFontSize
*/
public function testConstruct()
{
$object = new PHPWord();
$this->assertEquals(
new PHPWord_DocumentProperties(),
$object->getProperties()
);
$this->assertEquals(
PHPWord::DEFAULT_FONT_NAME,
$object->getDefaultFontName()
);
$this->assertEquals(
PHPWord::DEFAULT_FONT_SIZE,
$object->getDefaultFontSize()
);
}
/**
* @covers PHPWord::setProperties
* @covers PHPWord::getProperties
*/
public function testSetGetProperties()
{
$object = new PHPWord();
$creator = 'PHPWord';
$properties = $object->getProperties();
$properties->setCreator($creator);
$object->setProperties($properties);
$this->assertEquals($creator, $object->getProperties()->getCreator());
}
/**
* @covers PHPWord::createSection
* @covers PHPWord::getSections
*/
public function testCreateGetSections()
{
$object = new PHPWord();
$this->assertEquals(new PHPWord_Section(1), $object->createSection());
$object->createSection();
$this->assertEquals(2, count($object->getSections()));
}
/**
* @covers PHPWord::setDefaultFontName
* @covers PHPWord::getDefaultFontName
*/
public function testSetGetDefaultFontName()
{
$object = new PHPWord();
$fontName = 'Times New Roman';
$this->assertEquals(
PHPWord::DEFAULT_FONT_NAME,
$object->getDefaultFontName()
);
$object->setDefaultFontName($fontName);
$this->assertEquals($fontName, $object->getDefaultFontName());
}
/**
* @covers PHPWord::setDefaultFontSize
* @covers PHPWord::getDefaultFontSize
*/
public function testSetGetDefaultFontSize()
{
$object = new PHPWord();
$fontSize = 16;
$this->assertEquals(
PHPWord::DEFAULT_FONT_SIZE,
$object->getDefaultFontSize()
);
$object->setDefaultFontSize($fontSize);
$this->assertEquals($fontSize, $object->getDefaultFontSize());
}
/**
* @covers PHPWord::setDefaultParagraphStyle
* @covers PHPWord::loadTemplate
*/
public function testSetDefaultParagraphStyle()
{
$object = new PHPWord();
$object->setDefaultParagraphStyle(array());
$this->assertInstanceOf(
'PHPWord_Style_Paragraph',
PHPWord_Style::getStyle('Normal')
);
}
/**
* @covers PHPWord::addParagraphStyle
* @covers PHPWord::addFontStyle
* @covers PHPWord::addTableStyle
* @covers PHPWord::addLinkStyle
*/
public function testAddStyles()
{
$object = new PHPWord();
$styles = array('Paragraph' => 'Paragraph', 'Font' => 'Font',
'Table' => 'TableFull', 'Link' => 'Font');
foreach ($styles as $key => $value) {
$method = "add{$key}Style";
$styleId = "{$key} Style";
$styleType = "PHPWord_Style_{$value}";
$object->$method($styleId, array());
$this->assertInstanceOf(
$styleType,
PHPWord_Style::getStyle($styleId)
);
}
}
/**
* @covers PHPWord::addTitleStyle
*/
public function testAddTitleStyle()
{
$object = new PHPWord();
$titleLevel = 1;
$titleName = "Heading_{$titleLevel}";
$object->addTitleStyle($titleLevel, array());
$this->assertInstanceOf(
'PHPWord_Style_Font',
PHPWord_Style::getStyle($titleName)
);
}
/**
* @covers PHPWord::loadTemplate
*/
public function testLoadTemplate()
{
$file = join(
DIRECTORY_SEPARATOR,
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'templates', 'blank.docx')
);
$object = new PHPWord();
$this->assertInstanceOf(
'PHPWord_Template',
$object->loadTemplate($file)
);
}
/**
* @covers PHPWord::loadTemplate
* @expectedException PHPWord_Exception
*/
public function testLoadTemplateException()
{
$file = join(
DIRECTORY_SEPARATOR,
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'templates', 'blanks.docx')
);
$object = new PHPWord();
$object->loadTemplate($file);
}
}

Binary file not shown.

View File

@ -2,15 +2,15 @@
namespace PHPWord\Tests;
use PHPWord;
use DOMDocument;
class TestHelperDOCX
{
/** @var string $file */
static protected $file;
/**
* @param \PHPWord $PHPWord
* @return \PHPWord\Tests\Xml_Document
* @return \PHPWord\Tests\XmlDocument
*/
public static function getDocument(PHPWord $PHPWord)
{
@ -29,7 +29,7 @@ class TestHelperDOCX
$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()
@ -50,75 +50,21 @@ class TestHelperDOCX
foreach (scandir($dir) as $file) {
if ($file === '.' || $file === '..') {
continue;
} else if (is_file($dir . "/" . $file)) {
} elseif (is_file($dir . "/" . $file)) {
unlink($dir . "/" . $file);
} else if (is_dir($dir . "/" . $file)) {
} elseif (is_dir($dir . "/" . $file)) {
self::deleteDir($dir . "/" . $file);
}
}
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
* @return string
*/
public function __construct($path)
public static function getFile()
{
$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);
return self::$file;
}
}

View File

@ -0,0 +1,82 @@
<?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);
}
/**
* @return string
*/
public function getFile()
{
return $this->file;
}
/**
* @return string
*/
public function getPath()
{
return $this->path;
}
}

View File

@ -12,3 +12,4 @@ require_once __DIR__ . '/../Classes/PHPWord/Autoloader.php';
PHPWord_Autoloader::Register();
require_once __DIR__ . '/_inc/TestHelperDOCX.php';
require_once __DIR__ . '/_inc/XmlDocument.php';

View File

@ -50,6 +50,7 @@ Changes in branch for release 0.7.1 :
- Bugfix: (ivanlanin) GH-94 - General: PHPWord_Shared_Drawing::centimetersToPixels() conversion
- Feature: (ivanlanin) - Paragraph: setTabs() function
- Feature: (ivanlanin) GH-99 - General: Basic support for TextRun on ODT and RTF
- Feature: (ivanlanin) - Reader: Initial effort for Word2007
- QA: (Progi1984) - UnitTests
Changes in branch for release 0.7.0 :

View File

@ -0,0 +1,33 @@
<?php
// error_reporting(E_ALL );
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
require_once '../Classes/PHPWord.php';
// Read contents
$sample = 'Sample_10_ReadWord2007';
$source = "resources/{$sample}.docx";
$target = "results/{$sample}";
echo '<p><strong>', date('H:i:s'), " Reading contents from `{$source}`</strong></p>";
$PHPWord = PHPWord_IOFactory::load($source);
// Rewrite contents
echo date('H:i:s') , " Write to Word2007 format" , EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save("{$sample}.docx");
rename("{$sample}.docx", "{$target}.docx");
echo date('H:i:s') , ' Write to OpenDocumentText format' , EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'ODText');
$objWriter->save("{$sample}.odt");
rename("{$sample}.odt", "{$target}.odt");
echo date('H:i:s') , ' Write to RTF format' , EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'RTF');
$objWriter->save("{$sample}.rtf");
rename("{$sample}.rtf", "{$target}.rtf");
// Echo memory peak usage
echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
echo date('H:i:s') , " Done writing file" , EOL;

Binary file not shown.

0
samples/results/.gitkeep Normal file
View File