diff --git a/.travis.yml b/.travis.yml index 155a28e6..99f33a20 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: php php: - - 5.3.3 - 5.3 - 5.4 - 5.5 @@ -13,7 +12,7 @@ matrix: before_script: ## Composer - curl -s http://getcomposer.org/installer | php - - php composer.phar install + - php composer.phar install --prefer-source ## PHP_CodeSniffer - pyrus install pear/PHP_CodeSniffer - phpenv rehash @@ -36,9 +35,11 @@ script: ## PHP Copy/Paste Detector - php phpcpd.phar --verbose Classes/ ## PHP Mess Detector - - phpmd Classes/ text codesize,unusedcode,naming,design + - phpmd Classes/ text unusedcode,naming,design ## PHPLOC - php phploc.phar Classes/ + ## PHPUnit + - phpunit -c ./ --coverage-text notifications: email: diff --git a/Classes/PHPWord.php b/Classes/PHPWord.php index b930bfb5..37fd24d8 100755 --- a/Classes/PHPWord.php +++ b/Classes/PHPWord.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Autoloader.php b/Classes/PHPWord/Autoloader.php index 601c2ebf..0e740822 100755 --- a/Classes/PHPWord/Autoloader.php +++ b/Classes/PHPWord/Autoloader.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ @@ -31,9 +31,13 @@ if (!defined('PHPWORD_BASE_PATH')) { /** * Class PHPWord_Autoloader + * + * TODO: remove legacy autoloader once everything is moved to namespaces */ class PHPWord_Autoloader { + const PREFIX = 'PHPWord'; + /** * Register the autoloader * @@ -41,7 +45,8 @@ class PHPWord_Autoloader */ public static function register() { - spl_autoload_register(array('PHPWord_Autoloader', 'load')); + spl_autoload_register(array('PHPWord_Autoloader', 'load')); // Legacy + spl_autoload_register(array(new self, 'autoload')); // PSR-4 } /** @@ -60,4 +65,21 @@ class PHPWord_Autoloader return null; } + + /** + * Autoloader + * + * @param string + */ + public static function autoload($class) + { + $prefixLength = strlen(self::PREFIX); + if (0 === strncmp(self::PREFIX, $class, $prefixLength)) { + $file = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, $prefixLength)); + $file = realpath(__DIR__ . (empty($file) ? '' : DIRECTORY_SEPARATOR) . $file . '.php'); + if (file_exists($file)) { + require_once $file; + } + } + } } \ No newline at end of file diff --git a/Classes/PHPWord/DocumentProperties.php b/Classes/PHPWord/DocumentProperties.php index c96ac0d4..2bf44043 100755 --- a/Classes/PHPWord/DocumentProperties.php +++ b/Classes/PHPWord/DocumentProperties.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Exception.php b/Classes/PHPWord/Exception.php index d1da2099..bd73d52c 100755 --- a/Classes/PHPWord/Exception.php +++ b/Classes/PHPWord/Exception.php @@ -20,8 +20,8 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord - * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @copyright Copyright (c) 2014 PHPWord + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/HashTable.php b/Classes/PHPWord/HashTable.php index cb4f8539..5b6fbd04 100755 --- a/Classes/PHPWord/HashTable.php +++ b/Classes/PHPWord/HashTable.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,8 +20,8 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord - * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @copyright Copyright (c) 2014 PHPWord + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/IOFactory.php b/Classes/PHPWord/IOFactory.php index 9dd1c1ad..a9eae570 100755 --- a/Classes/PHPWord/IOFactory.php +++ b/Classes/PHPWord/IOFactory.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Media.php b/Classes/PHPWord/Media.php index b739d365..de913719 100755 --- a/Classes/PHPWord/Media.php +++ b/Classes/PHPWord/Media.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Section.php b/Classes/PHPWord/Section.php index 3bb11c1c..aeea4223 100755 --- a/Classes/PHPWord/Section.php +++ b/Classes/PHPWord/Section.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Section/Footer.php b/Classes/PHPWord/Section/Footer.php index a5de1891..6e5ae8f7 100755 --- a/Classes/PHPWord/Section/Footer.php +++ b/Classes/PHPWord/Section/Footer.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Section/Footer/PreserveText.php b/Classes/PHPWord/Section/Footer/PreserveText.php index a38b1dcc..9ec896c4 100755 --- a/Classes/PHPWord/Section/Footer/PreserveText.php +++ b/Classes/PHPWord/Section/Footer/PreserveText.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Section/Header.php b/Classes/PHPWord/Section/Header.php index 483f887e..cb91e085 100755 --- a/Classes/PHPWord/Section/Header.php +++ b/Classes/PHPWord/Section/Header.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Section/Image.php b/Classes/PHPWord/Section/Image.php index 4dbf8808..f4ad628f 100755 --- a/Classes/PHPWord/Section/Image.php +++ b/Classes/PHPWord/Section/Image.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Section/Link.php b/Classes/PHPWord/Section/Link.php index d3396c7d..42b9d7b3 100755 --- a/Classes/PHPWord/Section/Link.php +++ b/Classes/PHPWord/Section/Link.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Section/ListItem.php b/Classes/PHPWord/Section/ListItem.php index f70f8396..ac5263b3 100755 --- a/Classes/PHPWord/Section/ListItem.php +++ b/Classes/PHPWord/Section/ListItem.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Section/MemoryImage.php b/Classes/PHPWord/Section/MemoryImage.php index d4e8b6ff..9652955c 100755 --- a/Classes/PHPWord/Section/MemoryImage.php +++ b/Classes/PHPWord/Section/MemoryImage.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Section/Object.php b/Classes/PHPWord/Section/Object.php index 30d253dc..acf14e55 100755 --- a/Classes/PHPWord/Section/Object.php +++ b/Classes/PHPWord/Section/Object.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Section/PageBreak.php b/Classes/PHPWord/Section/PageBreak.php index d72c2318..f7be1cc7 100755 --- a/Classes/PHPWord/Section/PageBreak.php +++ b/Classes/PHPWord/Section/PageBreak.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Section/Settings.php b/Classes/PHPWord/Section/Settings.php index 487a9d19..fce8d7b1 100755 --- a/Classes/PHPWord/Section/Settings.php +++ b/Classes/PHPWord/Section/Settings.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ @@ -150,26 +150,23 @@ class PHPWord_Section_Settings */ private $_borderBottomColor; + /** - * Section Columns Count + * Page Numbering Start * * @var int */ - private $_colsNum; + private $pageNumberingStart; /** - * Section Spacing Between Columns - * * @var int */ - private $_colsSpace; + private $headerHeight; /** - * Section Break Type - * - * @var string + * @var int */ - private $_breakType; + private $footerHeight; /** * Create new Section Settings @@ -191,9 +188,8 @@ class PHPWord_Section_Settings $this->_borderRightColor = null; $this->_borderBottomSize = null; $this->_borderBottomColor = null; - $this->_colsNum = 1; - $this->_colsSpace = 720; - $this->_breakType = null; + $this->headerHeight = 720; // set default header and footer to 720 twips (.5 inches) + $this->footerHeight = 720; } /** @@ -568,59 +564,58 @@ class PHPWord_Section_Settings } /** - * Set Section Columns Count - * - * @param in $pValue + * @param null|int $pageNumberingStart + * @return $this */ - public function setColsNum($pValue = '') { - $this->_colsNum = $pValue; - return $this; - } + public function setPageNumberingStart($pageNumberingStart = null) + { + $this->pageNumberingStart = $pageNumberingStart; + return $this; + } /** - * Get Section Columns Count + * @return null|int + */ + public function getPageNumberingStart() + { + return $this->pageNumberingStart; + } + + /** + * Get Header Height * * @return int */ - public function getColsNum() { - return $this->_colsNum; - } + public function getHeaderHeight() { + return $this->headerHeight; + } /** - * Set Section Space Between Columns + * Set Header Height * * @param int $pValue */ - public function setColsSpace($pValue = '') { - $this->_colsSpace = $pValue; - return $this; - } + public function setHeaderHeight($pValue = '') { + $this->headerHeight = $pValue; + return $this; + } /** - * Get Section Space Between Columns + * Get Footer Height * * @return int */ - public function getColsSpace() { - return $this->_colsSpace; - } + public function getFooterHeight() { + return $this->footerHeight; + } /** - * Set Break Type + * Set Footer Height * - * @param string $pValue + * @param int $pValue */ - public function setBreakType($pValue = null) { - $this->_breakType = $pValue; - return $this; - } - - /** - * Get Break Type - * - * @return string - */ - public function getBreakType() { - return $this->_breakType; - } + public function setFooterHeight($pValue = '') { + $this->footerHeight = $pValue; + return $this; + } } diff --git a/Classes/PHPWord/Section/Table.php b/Classes/PHPWord/Section/Table.php index 157bf070..081b6484 100755 --- a/Classes/PHPWord/Section/Table.php +++ b/Classes/PHPWord/Section/Table.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Section/Table/Cell.php b/Classes/PHPWord/Section/Table/Cell.php index cf6f1dc8..b4bc8242 100755 --- a/Classes/PHPWord/Section/Table/Cell.php +++ b/Classes/PHPWord/Section/Table/Cell.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ @@ -80,11 +80,10 @@ class PHPWord_Section_Table_Cell $this->_insideOf = $insideOf; $this->_pCount = $pCount; $this->_width = $width; + $this->_style = new PHPWord_Style_Cell; if (!is_null($style)) { if (is_array($style)) { - $this->_style = new PHPWord_Style_Cell(); - foreach ($style as $key => $value) { if (substr($key, 0, 1) != '_') { $key = '_' . $key; diff --git a/Classes/PHPWord/Section/Text.php b/Classes/PHPWord/Section/Text.php index aa6266e7..2b37e7d4 100755 --- a/Classes/PHPWord/Section/Text.php +++ b/Classes/PHPWord/Section/Text.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Section/TextBreak.php b/Classes/PHPWord/Section/TextBreak.php index cf4ef563..173672ec 100755 --- a/Classes/PHPWord/Section/TextBreak.php +++ b/Classes/PHPWord/Section/TextBreak.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Section/TextRun.php b/Classes/PHPWord/Section/TextRun.php index cfa5bc6c..44473e63 100755 --- a/Classes/PHPWord/Section/TextRun.php +++ b/Classes/PHPWord/Section/TextRun.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ @@ -110,15 +110,26 @@ class PHPWord_Section_TextRun } /** - * Add a TextBreak Element - * - * @param int $count - */ - public function addTextBreak($count = 1) { - for($i=1; $i<=$count; $i++) { - $this->_elementCollection[] = new PHPWord_Section_TextBreak(); + * Add a Image Element + * + * @param string $imageSrc + * @param mixed $styleFont + * @return PHPWord_Section_Image + */ + public function addImage($imageSrc, $style = null) { + $image = new PHPWord_Section_Image($imageSrc, $style); + + if (!is_null($image->getSource())) { + $rID = PHPWord_Media::addSectionMediaElement($imageSrc, 'image'); + $image->setRelationId($rID); + + $this->_elementCollection[] = $image; + return $image; + } else { + trigger_error('Source does not exist or unsupported image type.'); } } + /** * Get TextRun content * diff --git a/Classes/PHPWord/Section/Title.php b/Classes/PHPWord/Section/Title.php index a1de15cf..8dd5f1c3 100755 --- a/Classes/PHPWord/Section/Title.php +++ b/Classes/PHPWord/Section/Title.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Shared/Drawing.php b/Classes/PHPWord/Shared/Drawing.php index eadf0b19..dba204e3 100755 --- a/Classes/PHPWord/Shared/Drawing.php +++ b/Classes/PHPWord/Shared/Drawing.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Shared/File.php b/Classes/PHPWord/Shared/File.php index f09b3849..7c1470fe 100755 --- a/Classes/PHPWord/Shared/File.php +++ b/Classes/PHPWord/Shared/File.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Shared/Font.php b/Classes/PHPWord/Shared/Font.php index 28b6c2e5..be3cf1a8 100755 --- a/Classes/PHPWord/Shared/Font.php +++ b/Classes/PHPWord/Shared/Font.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Shared/String.php b/Classes/PHPWord/Shared/String.php index ca331642..f570e6b7 100755 --- a/Classes/PHPWord/Shared/String.php +++ b/Classes/PHPWord/Shared/String.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Shared/XMLWriter.php b/Classes/PHPWord/Shared/XMLWriter.php index a8e8377e..2795083e 100755 --- a/Classes/PHPWord/Shared/XMLWriter.php +++ b/Classes/PHPWord/Shared/XMLWriter.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Shared/ZipStreamWrapper.php b/Classes/PHPWord/Shared/ZipStreamWrapper.php index 57f06fca..0dc42875 100755 --- a/Classes/PHPWord/Shared/ZipStreamWrapper.php +++ b/Classes/PHPWord/Shared/ZipStreamWrapper.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Style.php b/Classes/PHPWord/Style.php index 7255e557..7b20f8ab 100755 --- a/Classes/PHPWord/Style.php +++ b/Classes/PHPWord/Style.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Style/Cell.php b/Classes/PHPWord/Style/Cell.php index 8bc224a9..e7d2bf91 100755 --- a/Classes/PHPWord/Style/Cell.php +++ b/Classes/PHPWord/Style/Cell.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Style/Font.php b/Classes/PHPWord/Style/Font.php index 293d7e35..3363dc66 100755 --- a/Classes/PHPWord/Style/Font.php +++ b/Classes/PHPWord/Style/Font.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Style/Image.php b/Classes/PHPWord/Style/Image.php index 422ddfb8..47a71cba 100755 --- a/Classes/PHPWord/Style/Image.php +++ b/Classes/PHPWord/Style/Image.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Style/ListItem.php b/Classes/PHPWord/Style/ListItem.php index 8eb7ffa2..9429b47e 100755 --- a/Classes/PHPWord/Style/ListItem.php +++ b/Classes/PHPWord/Style/ListItem.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Style/Paragraph.php b/Classes/PHPWord/Style/Paragraph.php index d7e7f508..3c2639be 100755 --- a/Classes/PHPWord/Style/Paragraph.php +++ b/Classes/PHPWord/Style/Paragraph.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Style/TOC.php b/Classes/PHPWord/Style/TOC.php index 41eaefc4..501604b4 100755 --- a/Classes/PHPWord/Style/TOC.php +++ b/Classes/PHPWord/Style/TOC.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Style/Tab.php b/Classes/PHPWord/Style/Tab.php index c35f04cb..a280eebb 100755 --- a/Classes/PHPWord/Style/Tab.php +++ b/Classes/PHPWord/Style/Tab.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Style/Table.php b/Classes/PHPWord/Style/Table.php index 02a794aa..73def233 100755 --- a/Classes/PHPWord/Style/Table.php +++ b/Classes/PHPWord/Style/Table.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Style/TableFull.php b/Classes/PHPWord/Style/TableFull.php index b359a592..4e2a7686 100755 --- a/Classes/PHPWord/Style/TableFull.php +++ b/Classes/PHPWord/Style/TableFull.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Style/Tabs.php b/Classes/PHPWord/Style/Tabs.php index c98d472e..ebad8fbb 100755 --- a/Classes/PHPWord/Style/Tabs.php +++ b/Classes/PHPWord/Style/Tabs.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/TOC.php b/Classes/PHPWord/TOC.php index 994ff2c3..1366f0c3 100755 --- a/Classes/PHPWord/TOC.php +++ b/Classes/PHPWord/TOC.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Template.php b/Classes/PHPWord/Template.php index a01a8541..95461626 100755 --- a/Classes/PHPWord/Template.php +++ b/Classes/PHPWord/Template.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ @@ -81,8 +81,9 @@ class PHPWord_Template * * @param mixed $search * @param mixed $replace + * @param integer $limit */ - public function setValue($search, $replace) + public function setValue($search, $replace, $limit = -1) { $pattern = '|\$\{([^\}]+)\}|U'; preg_match_all($pattern, $this->_documentXML, $matches); @@ -102,7 +103,12 @@ class PHPWord_Template } } - $this->_documentXML = str_replace($search, $replace, $this->_documentXML); + $regExpDelim = '/'; + $escapedSearch = preg_quote($search, $regExpDelim); + $this->_documentXML = preg_replace("{$regExpDelim}{$escapedSearch}{$regExpDelim}u", + $replace, + $this->_documentXML, + $limit); } /** @@ -117,14 +123,9 @@ class PHPWord_Template /** * Save Template * - * @param string $strFilename + * @return string */ - public function save($strFilename) - { - if (file_exists($strFilename)) { - unlink($strFilename); - } - + public function save() { $this->_objZip->addFromString('word/document.xml', $this->_documentXML); // Close zip file @@ -132,6 +133,21 @@ class PHPWord_Template throw new Exception('Could not close zip file.'); } - rename($this->_tempFileName, $strFilename); + return $this->_tempFileName; } -} \ No newline at end of file + + /** + * Save Template As... + * + * @param string $strFilename + */ + public function saveAs($strFilename) { + $tempFilename = $this->save(); + + if (file_exists($strFilename)) { + unlink($strFilename); + } + + rename($tempFilename, $strFilename); + } +} diff --git a/Classes/PHPWord/Writer/IWriter.php b/Classes/PHPWord/Writer/IWriter.php index 545c29a8..eb561d1b 100755 --- a/Classes/PHPWord/Writer/IWriter.php +++ b/Classes/PHPWord/Writer/IWriter.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Writer/ODText.php b/Classes/PHPWord/Writer/ODText.php index 19e55f60..3414179d 100755 --- a/Classes/PHPWord/Writer/ODText.php +++ b/Classes/PHPWord/Writer/ODText.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,8 +20,8 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord - * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @copyright Copyright (c) 2014 PHPWord + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Writer/ODText/Content.php b/Classes/PHPWord/Writer/ODText/Content.php index f8784e10..84806f48 100755 --- a/Classes/PHPWord/Writer/ODText/Content.php +++ b/Classes/PHPWord/Writer/ODText/Content.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,8 +20,8 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord - * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @copyright Copyright (c) 2014 PHPWord + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Writer/ODText/Manifest.php b/Classes/PHPWord/Writer/ODText/Manifest.php index 5509073b..f9815941 100755 --- a/Classes/PHPWord/Writer/ODText/Manifest.php +++ b/Classes/PHPWord/Writer/ODText/Manifest.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,8 +20,8 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord - * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @copyright Copyright (c) 2014 PHPWord + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Writer/ODText/Meta.php b/Classes/PHPWord/Writer/ODText/Meta.php index ca6d305c..79624d82 100755 --- a/Classes/PHPWord/Writer/ODText/Meta.php +++ b/Classes/PHPWord/Writer/ODText/Meta.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,8 +20,8 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord - * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @copyright Copyright (c) 2014 PHPWord + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Writer/ODText/Mimetype.php b/Classes/PHPWord/Writer/ODText/Mimetype.php index f6348f48..439ada1a 100755 --- a/Classes/PHPWord/Writer/ODText/Mimetype.php +++ b/Classes/PHPWord/Writer/ODText/Mimetype.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,8 +20,8 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord - * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @copyright Copyright (c) 2014 PHPWord + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Writer/ODText/Styles.php b/Classes/PHPWord/Writer/ODText/Styles.php index 7830db78..fd56b7fa 100755 --- a/Classes/PHPWord/Writer/ODText/Styles.php +++ b/Classes/PHPWord/Writer/ODText/Styles.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,8 +20,8 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord - * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @copyright Copyright (c) 2014 PHPWord + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Writer/ODText/WriterPart.php b/Classes/PHPWord/Writer/ODText/WriterPart.php index 5d95d69c..1e05cd50 100755 --- a/Classes/PHPWord/Writer/ODText/WriterPart.php +++ b/Classes/PHPWord/Writer/ODText/WriterPart.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,8 +20,8 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord - * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @copyright Copyright (c) 2014 PHPWord + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Writer/RTF.php b/Classes/PHPWord/Writer/RTF.php index 3f5b73ee..42b544fb 100755 --- a/Classes/PHPWord/Writer/RTF.php +++ b/Classes/PHPWord/Writer/RTF.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,8 +20,8 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord - * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @copyright Copyright (c) 2014 PHPWord + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Writer/Word2007.php b/Classes/PHPWord/Writer/Word2007.php index 91706ab2..6dfc95d3 100755 --- a/Classes/PHPWord/Writer/Word2007.php +++ b/Classes/PHPWord/Writer/Word2007.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Writer/Word2007/Base.php b/Classes/PHPWord/Writer/Word2007/Base.php index aedd4f50..a90126d9 100755 --- a/Classes/PHPWord/Writer/Word2007/Base.php +++ b/Classes/PHPWord/Writer/Word2007/Base.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ @@ -106,8 +106,8 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart $this->_writeText($objWriter, $element, true); } elseif ($element instanceof PHPWord_Section_Link) { $this->_writeLink($objWriter, $element, true); - } elseif($element instanceof PHPWord_Section_TextBreak) { - $objWriter->writeElement('w:br'); + } elseif ($element instanceof PHPWord_Section_Image) { + $this->_writeImage($objWriter, $element, true); } } } @@ -122,7 +122,6 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart $spaceAfter = $style->getSpaceAfter(); $spacing = $style->getSpacing(); $indent = $style->getIndent(); - $hanging = $style->getHanging(); $tabs = $style->getTabs(); if (!is_null($align) || !is_null($spacing) || !is_null($spaceBefore) || !is_null($spaceAfter) || !is_null($indent) || !is_null($tabs)) { @@ -136,15 +135,10 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart $objWriter->endElement(); } - if (!is_null($indent) || !is_null($hanging)) { + if (!is_null($indent)) { $objWriter->startElement('w:ind'); $objWriter->writeAttribute('w:firstLine', 0); - if (!is_null($indent)) { - $objWriter->writeAttribute('w:left', $indent); - } - if (!is_null($hanging)) { - $objWriter->writeAttribute('w:hanging', $hanging); - } + $objWriter->writeAttribute('w:left', $indent); $objWriter->endElement(); } @@ -328,13 +322,11 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart $fgColor = $style->getFgColor(); $striketrough = $style->getStrikethrough(); $underline = $style->getUnderline(); - $superscript = $style->getSuperScript(); - $subscript = $style->getSubScript(); $objWriter->startElement('w:rPr'); // Font - if ($font != PHPWord::DEFAULT_FONT_NAME) { + if ($font != 'Arial') { $objWriter->startElement('w:rFonts'); $objWriter->writeAttribute('w:ascii', $font); $objWriter->writeAttribute('w:hAnsi', $font); @@ -350,7 +342,7 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart } // Size - if ($size != PHPWord::DEFAULT_FONT_SIZE) { + if ($size != 20) { $objWriter->startElement('w:sz'); $objWriter->writeAttribute('w:val', $size); $objWriter->endElement(); @@ -389,13 +381,6 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart $objWriter->endElement(); } - // Superscript/subscript - if ($superscript || $subscript) { - $objWriter->startElement('w:vertAlign'); - $objWriter->writeAttribute('w:val', $superscript ? 'superscript' : 'subscript'); - $objWriter->endElement(); - } - $objWriter->endElement(); } @@ -412,7 +397,6 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart if ($_cRows > 0) { $objWriter->startElement('w:tbl'); $tblStyle = $table->getStyle(); - $tblWidth = $table->getWidth(); if ($tblStyle instanceof PHPWord_Style_Table) { $this->_writeTableStyle($objWriter, $tblStyle); } else { @@ -421,46 +405,26 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart $objWriter->startElement('w:tblStyle'); $objWriter->writeAttribute('w:val', $tblStyle); $objWriter->endElement(); - if (!is_null($tblWidth)) { - $objWriter->startElement('w:tblW'); - $objWriter->writeAttribute('w:w', $tblWidth); - $objWriter->writeAttribute('w:type', 'pct'); - $objWriter->endElement(); - } $objWriter->endElement(); } } + $_heights = $table->getRowHeights(); for ($i = 0; $i < $_cRows; $i++) { $row = $_rows[$i]; - $height = $row->getHeight(); - $rowStyle = $row->getStyle(); - $tblHeader = $rowStyle->getTblHeader(); - $cantSplit = $rowStyle->getCantSplit(); + $height = $_heights[$i]; $objWriter->startElement('w:tr'); - if (!is_null($height) || !is_null($tblHeader) || !is_null($cantSplit)) { + if (!is_null($height)) { $objWriter->startElement('w:trPr'); - if (!is_null($height)) { - $objWriter->startElement('w:trHeight'); - $objWriter->writeAttribute('w:val', $height); - $objWriter->endElement(); - } - if (!is_null($tblHeader)) { - $objWriter->startElement('w:tblHeader'); - $objWriter->writeAttribute('w:val', $tblHeader); - $objWriter->endElement(); - } - if (!is_null($cantSplit)) { - $objWriter->startElement('w:cantSplit'); - $objWriter->writeAttribute('w:val', $cantSplit); - $objWriter->endElement(); - } + $objWriter->startElement('w:trHeight'); + $objWriter->writeAttribute('w:val', $height); + $objWriter->endElement(); $objWriter->endElement(); } - foreach ($row->getCells() as $cell) { + foreach ($row as $cell) { $objWriter->startElement('w:tc'); $cellStyle = $cell->getStyle(); @@ -469,7 +433,7 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart $objWriter->startElement('w:tcPr'); $objWriter->startElement('w:tcW'); $objWriter->writeAttribute('w:w', $width); - $objWriter->writeAttribute('w:type', 'pct'); + $objWriter->writeAttribute('w:type', 'dxa'); $objWriter->endElement(); if ($cellStyle instanceof PHPWord_Style_Cell) { @@ -665,7 +629,7 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart * @param \PHPWord_Shared_XMLWriter $objWriter * @param \PHPWord_Section_Image $image */ - protected function _writeImage(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Image $image) + protected function _writeImage(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Image $image, $withoutP = false) { $rId = $image->getRelationId(); @@ -677,14 +641,16 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart $marginLeft = $style->getMarginLeft(); $wrappingStyle = $style->getWrappingStyle(); - $objWriter->startElement('w:p'); + if (!$withoutP) { + $objWriter->startElement('w:p'); - if (!is_null($align)) { - $objWriter->startElement('w:pPr'); - $objWriter->startElement('w:jc'); - $objWriter->writeAttribute('w:val', $align); - $objWriter->endElement(); - $objWriter->endElement(); + if (!is_null($align)) { + $objWriter->startElement('w:pPr'); + $objWriter->startElement('w:jc'); + $objWriter->writeAttribute('w:val', $align); + $objWriter->endElement(); + $objWriter->endElement(); + } } $objWriter->startElement('w:r'); @@ -735,7 +701,9 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart $objWriter->endElement(); - $objWriter->endElement(); + if (!$withoutP) { + $objWriter->endElement(); // w:p + } } protected function _writeWatermark(PHPWord_Shared_XMLWriter $objWriter = null, $image) diff --git a/Classes/PHPWord/Writer/Word2007/ContentTypes.php b/Classes/PHPWord/Writer/Word2007/ContentTypes.php index 6ec85179..0c8da192 100755 --- a/Classes/PHPWord/Writer/Word2007/ContentTypes.php +++ b/Classes/PHPWord/Writer/Word2007/ContentTypes.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Writer/Word2007/DocProps.php b/Classes/PHPWord/Writer/Word2007/DocProps.php index 2740d8da..be633419 100755 --- a/Classes/PHPWord/Writer/Word2007/DocProps.php +++ b/Classes/PHPWord/Writer/Word2007/DocProps.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Writer/Word2007/Document.php b/Classes/PHPWord/Writer/Word2007/Document.php index 738476cd..b49b534d 100755 --- a/Classes/PHPWord/Writer/Word2007/Document.php +++ b/Classes/PHPWord/Writer/Word2007/Document.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ @@ -123,19 +123,22 @@ class PHPWord_Writer_Word2007_Document extends PHPWord_Writer_Word2007_Base private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section) { - $_settings = $section->getSettings(); + $settings = $section->getSettings(); $_headers = $section->getHeaders(); $_footer = $section->getFooter(); - $pgSzW = $_settings->getPageSizeW(); - $pgSzH = $_settings->getPageSizeH(); - $orientation = $_settings->getOrientation(); + $pgSzW = $settings->getPageSizeW(); + $pgSzH = $settings->getPageSizeH(); + $orientation = $settings->getOrientation(); - $marginTop = $_settings->getMarginTop(); - $marginLeft = $_settings->getMarginLeft(); - $marginRight = $_settings->getMarginRight(); - $marginBottom = $_settings->getMarginBottom(); + $marginTop = $settings->getMarginTop(); + $marginLeft = $settings->getMarginLeft(); + $marginRight = $settings->getMarginRight(); + $marginBottom = $settings->getMarginBottom(); - $borders = $_settings->getBorderSize(); + $headerHeight = $settings->getHeaderHeight(); + $footerHeight = $settings->getFooterHeight(); + + $borders = $settings->getBorderSize(); $colsNum = $_settings->getColsNum(); $colsSpace = $_settings->getColsSpace(); @@ -186,14 +189,14 @@ class PHPWord_Writer_Word2007_Document extends PHPWord_Writer_Word2007_Base $objWriter->writeAttribute('w:right', $marginRight); $objWriter->writeAttribute('w:bottom', $marginBottom); $objWriter->writeAttribute('w:left', $marginLeft); - $objWriter->writeAttribute('w:header', '720'); - $objWriter->writeAttribute('w:footer', '720'); + $objWriter->writeAttribute('w:header', $headerHeight); + $objWriter->writeAttribute('w:footer', $footerHeight); $objWriter->writeAttribute('w:gutter', '0'); $objWriter->endElement(); if (!is_null($borders[0]) || !is_null($borders[1]) || !is_null($borders[2]) || !is_null($borders[3])) { - $borderColor = $_settings->getBorderColor(); + $borderColor = $settings->getBorderColor(); $objWriter->startElement('w:pgBorders'); $objWriter->writeAttribute('w:offsetFrom', 'page'); @@ -236,6 +239,12 @@ class PHPWord_Writer_Word2007_Document extends PHPWord_Writer_Word2007_Base $objWriter->endElement(); } + // Page numbering + if (null !== $settings->getPageNumberingStart()) { + $objWriter->startElement('w:pgNumType'); + $objWriter->writeAttribute('w:start', $section->getSettings()->getPageNumberingStart()); + $objWriter->endElement(); + } $objWriter->startElement('w:cols'); if($colsNum > 1){ @@ -261,7 +270,7 @@ class PHPWord_Writer_Word2007_Document extends PHPWord_Writer_Word2007_Base $objWriter->endElement(); } - private function _writeListItem(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_ListItem $listItem) + public function _writeListItem(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_ListItem $listItem) { $textObject = $listItem->getTextObject(); $text = $textObject->getText(); diff --git a/Classes/PHPWord/Writer/Word2007/DocumentRels.php b/Classes/PHPWord/Writer/Word2007/DocumentRels.php index b284f0b9..e5aaffbd 100755 --- a/Classes/PHPWord/Writer/Word2007/DocumentRels.php +++ b/Classes/PHPWord/Writer/Word2007/DocumentRels.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Writer/Word2007/Footer.php b/Classes/PHPWord/Writer/Word2007/Footer.php index 363e0531..1cd49771 100755 --- a/Classes/PHPWord/Writer/Word2007/Footer.php +++ b/Classes/PHPWord/Writer/Word2007/Footer.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Writer/Word2007/Header.php b/Classes/PHPWord/Writer/Word2007/Header.php index 4f4eacd8..4106d197 100755 --- a/Classes/PHPWord/Writer/Word2007/Header.php +++ b/Classes/PHPWord/Writer/Word2007/Header.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Writer/Word2007/Rels.php b/Classes/PHPWord/Writer/Word2007/Rels.php index 6d72839b..97f28d22 100755 --- a/Classes/PHPWord/Writer/Word2007/Rels.php +++ b/Classes/PHPWord/Writer/Word2007/Rels.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Writer/Word2007/Styles.php b/Classes/PHPWord/Writer/Word2007/Styles.php index fb39b57b..ded0a161 100755 --- a/Classes/PHPWord/Writer/Word2007/Styles.php +++ b/Classes/PHPWord/Writer/Word2007/Styles.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/Classes/PHPWord/Writer/Word2007/WriterPart.php b/Classes/PHPWord/Writer/Word2007/WriterPart.php index a6168a84..91a863e0 100755 --- a/Classes/PHPWord/Writer/Word2007/WriterPart.php +++ b/Classes/PHPWord/Writer/Word2007/WriterPart.php @@ -2,7 +2,7 @@ /** * PHPWord * - * Copyright (c) 2013 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,7 +20,7 @@ * * @category PHPWord * @package PHPWord - * @copyright Copyright (c) 2013 PHPWord + * @copyright Copyright (c) 2014 PHPWord * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.7.0 */ diff --git a/README.md b/README.md index 6ef55f31..a9f92603 100755 --- a/README.md +++ b/README.md @@ -1,21 +1,21 @@ -# PHPWord - OpenXML - Read, Write and Create Word documents in PHP +# PHPWord + +[![Build Status](https://travis-ci.org/PHPOffice/PHPWord.png?branch=master)](https://travis-ci.org/PHPOffice/PHPWord) +[![Latest Stable Version](https://poser.pugx.org/phpoffice/phpword/v/stable.png)](https://packagist.org/packages/phpoffice/phpword) [![Total Downloads](https://poser.pugx.org/phpoffice/phpword/downloads.png)](https://packagist.org/packages/phpoffice/phpword) [![Latest Unstable Version](https://poser.pugx.org/phpoffice/phpword/v/unstable.png)](https://packagist.org/packages/phpoffice/phpword) [![License](https://poser.pugx.org/phpoffice/phpword/license.png)](https://packagist.org/packages/phpoffice/phpword) + +__OpenXML - Read, Write and Create Word documents in PHP.__ PHPWord is a library written in PHP that create word documents. + No Windows operating system is needed for usage because the result are docx files (Office Open XML) that can be opened by all major office software. -Test patch branch - -## Want to contribute? -Fork us! +__Want to contribute?__ Fork us! ## Requirements * PHP version 5.3.0 or higher -## License -PHPWord is licensed under [LGPL (GNU LESSER GENERAL PUBLIC LICENSE)](https://github.com/PHPOffice/PHPWord/blob/master/license.md) - ## Installation It is recommended that you install the PHPWord library [through composer](http://getcomposer.org/). To do so, add @@ -29,7 +29,19 @@ the following lines to your ``composer.json``. } ``` -## Usage +## Documentation + +### Table of contents + +1. [Basic usage](#basic-usage) +2. [Sections](#sections) + * [Change Section Page Numbering](#sections-page-numbering) +3. [Tables](#tables) + * [Cell Style](#tables-cell-style) +4. [Images](#images) + + +#### Basic usage The following is a basic example of the PHPWord library. @@ -61,7 +73,44 @@ $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); $objWriter->save('helloWorld.docx'); ``` -## Images + +#### Sections + + +##### Change Section Page Numbering + +You can change a section page numbering. + +```php +$section = $PHPWord->createSection(); +$section->getSettings()->setPageNumberingStart(1); +``` + + +#### Tables + +The following illustrates how to create a table. + +```php +$table = $section->addTable(); +$table->addRow(); +$table->addCell(); +``` + + +##### Cell Style + +###### Cell Span + +You can span a cell on multiple columms. + +```php +$cell = $table->addCell(200); +$cell->getStyle()->setGridSpan(5); +``` + + +#### Images You can add images easily using the following example. @@ -71,16 +120,16 @@ $section->addImage('mars.jpg'); ``` Images settings include: - * ``width`` width in pixels - * ``height`` height in pixels - * ``align`` image alignment, __left__, __right__ or __center__ - * ``marginTop`` top margin in inches, can be negative - * ``marginLeft`` left margin in inches, can be negative - * ``wrappingStyle`` can be inline, __square__, __tight__, __behind__, __infront__ +* ``width`` width in pixels +* ``height`` height in pixels +* ``align`` image alignment, _left_, _right_ or _center_ +* ``marginTop`` top margin in inches, can be negative +* ``marginLeft`` left margin in inches, can be negative +* ``wrappingStyle`` can be _inline_, _square_, _tight_, _behind_, _infront_ - To add an image with settings, consider the following example. +To add an image with settings, consider the following example. - ```php +```php $section->addImage( 'mars.jpg', array( @@ -88,7 +137,7 @@ $section->addImage( 'height' => 100, 'marginTop' => -1, 'marginLeft' => -1, - wrappingStyle => 'behind' + 'wrappingStyle' => 'behind' ) ); ``` diff --git a/Tests/PHPWord/AutoloaderTest.php b/Tests/PHPWord/AutoloaderTest.php new file mode 100644 index 00000000..f24c04e8 --- /dev/null +++ b/Tests/PHPWord/AutoloaderTest.php @@ -0,0 +1,32 @@ +assertContains(array('PHPWord_Autoloader', 'load'), spl_autoload_functions()); + $this->assertContains(array('PHPWord_Autoloader', 'autoload'), spl_autoload_functions()); + } + + 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'); + } + + public function testAutoload() + { + $declared = get_declared_classes(); + $declaredCount = count($declared); + Autoloader::autoload('Foo'); + $this->assertEquals($declaredCount, count(get_declared_classes()), 'PHPWord\\Autoloader::autoload() is trying to load classes outside of the PHPWord namespace'); + Autoloader::autoload('PHPWord\\Exceptions\\InvalidStyleException'); // TODO change this class to the main PHPWord class when it is namespaced + $this->assertTrue(in_array('PHPWord\\Exceptions\\InvalidStyleException', get_declared_classes()), 'PHPWord\\Autoloader::autoload() failed to autoload the PHPWord\\Exceptions\\InvalidStyleException class'); + } +} \ No newline at end of file diff --git a/Tests/PHPWord/IOFactoryTest.php b/Tests/PHPWord/IOFactoryTest.php new file mode 100644 index 00000000..f6f0aba8 --- /dev/null +++ b/Tests/PHPWord/IOFactoryTest.php @@ -0,0 +1,59 @@ +assertAttributeEquals(PHPWord_IOFactory::getSearchLocations(), '_searchLocations','PHPWord_IOFactory'); + } + + public function testSetSearchLocationsWithArray() + { + PHPWord_IOFactory::setSearchLocations(array()); + $this->assertAttributeEquals(array(), '_searchLocations','PHPWord_IOFactory'); + } + + /** + * @expectedException Exception + * @expectedExceptionMessage Invalid parameter passed. + */ + public function testSetSearchLocationsWithNotArray() + { + PHPWord_IOFactory::setSearchLocations('String'); + } + + public function testAddSearchLocation() + { + PHPWord_IOFactory::setSearchLocations(array()); + PHPWord_IOFactory::addSearchLocation('type', 'location', 'classname'); + $this->assertAttributeEquals(array(array('type' => 'type', 'path' => 'location', 'class' => 'classname')), '_searchLocations','PHPWord_IOFactory'); + } + + /** + * @expectedException Exception + * @expectedExceptionMessage No IWriter found for type + */ + public function testCreateWriterException(){ + $oPHPWord = new PHPWord(); + + PHPWord_IOFactory::setSearchLocations(array()); + PHPWord_IOFactory::createWriter($oPHPWord); + } + + public function testCreateWriter(){ + $oPHPWord = new PHPWord(); + + $this->assertEquals(PHPWord_IOFactory::createWriter($oPHPWord, 'Word2007'), new PHPWord_Writer_Word2007($oPHPWord)); + } +} + \ No newline at end of file diff --git a/Tests/PHPWord/MediaTest.php b/Tests/PHPWord/MediaTest.php new file mode 100644 index 00000000..40460dea --- /dev/null +++ b/Tests/PHPWord/MediaTest.php @@ -0,0 +1,29 @@ +assertEquals(PHPWord_Media::getSectionMediaElements(), array()); + } + + public function testCountSectionMediaElementsWithNull() + { + $this->assertEquals(PHPWord_Media::countSectionMediaElements(), 0); + } + + public function testGetHeaderMediaElements() + { + $this->assertAttributeEquals(PHPWord_Media::getHeaderMediaElements(), '_headerMedia','PHPWord_Media'); + } + + public function testGetFooterMediaElements() + { + $this->assertAttributeEquals(PHPWord_Media::getFooterMediaElements(), '_footerMedia','PHPWord_Media'); + } +} + \ No newline at end of file diff --git a/Tests/PHPWord/SectionTest.php b/Tests/PHPWord/SectionTest.php new file mode 100644 index 00000000..0e90961d --- /dev/null +++ b/Tests/PHPWord/SectionTest.php @@ -0,0 +1,38 @@ +assertAttributeEquals($oSection->getSettings(), '_settings', new PHPWord_Section(0)); + } + + public function testGetElementss() + { + $oSection = new PHPWord_Section(0); + $this->assertAttributeEquals($oSection->getElements(), '_elementCollection',new PHPWord_Section(0)); + } + + public function testGetFooter() + { + $oSection = new PHPWord_Section(0); + $this->assertAttributeEquals($oSection->getFooter(), '_footer',new PHPWord_Section(0)); + } + + public function testGetHeaders() + { + $oSection = new PHPWord_Section(0); + $this->assertAttributeEquals($oSection->getHeaders(), '_headers',new PHPWord_Section(0)); + } + + public function testGetElements() + { + $oSection = new PHPWord_Section(0); + $this->assertAttributeEquals($oSection->getElements(), '_elementCollection',new PHPWord_Section(0)); + } +} + \ No newline at end of file diff --git a/Tests/PHPWord/Writer/Word2007/BaseTest.php b/Tests/PHPWord/Writer/Word2007/BaseTest.php new file mode 100644 index 00000000..8788af8b --- /dev/null +++ b/Tests/PHPWord/Writer/Word2007/BaseTest.php @@ -0,0 +1,82 @@ +createSection(); + $section->addImage( + PHPWORD_TESTS_DIR_ROOT . '/_files/images/earth.jpg', + array( + 'marginTop' => -1, + 'marginLeft' => -1, + 'wrappingStyle' => 'behind' + ) + ); + + $doc = TestHelperDOCX::getDocument($PHPWord); + $element = $doc->getElement('/w:document/w:body/w:p/w:r/w:pict/v:shape'); + + $style = $element->getAttribute('style'); + + $this->assertRegExp('/z\-index:\-[0-9]*/', $style); + $this->assertRegExp('/position:absolute;/', $style); + } + + public function testWriteParagraphStyle_Align() + { + $PHPWord = new PHPWord(); + $section = $PHPWord->createSection(); + + $section->addText('This is my text', null, array('align' => 'right')); + + $doc = TestHelperDOCX::getDocument($PHPWord); + $element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:jc'); + + $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')); + } +} + \ No newline at end of file diff --git a/Tests/PHPWord/Writer/Word2007/DocumentTest.php b/Tests/PHPWord/Writer/Word2007/DocumentTest.php new file mode 100644 index 00000000..13d233cc --- /dev/null +++ b/Tests/PHPWord/Writer/Word2007/DocumentTest.php @@ -0,0 +1,35 @@ +createSection(); + $section->getSettings()->setPageNumberingStart(2); + + $doc = TestHelperDOCX::getDocument($PHPWord); + $element = $doc->getElement('/w:document/w:body/w:sectPr/w:pgNumType'); + + $this->assertEquals(2, $element->getAttribute('w:start')); + } +} + \ No newline at end of file diff --git a/test/PHPWord/Tests/_files/images/earth.jpg b/Tests/_files/images/earth.jpg similarity index 100% rename from test/PHPWord/Tests/_files/images/earth.jpg rename to Tests/_files/images/earth.jpg diff --git a/test/PHPWord/Tests/_files/images/mars.jpg b/Tests/_files/images/mars.jpg similarity index 100% rename from test/PHPWord/Tests/_files/images/mars.jpg rename to Tests/_files/images/mars.jpg diff --git a/test/PHPWord/TestHelper.php b/Tests/_inc/TestHelperDOCX.php similarity index 73% rename from test/PHPWord/TestHelper.php rename to Tests/_inc/TestHelperDOCX.php index db626428..32f1af08 100644 --- a/test/PHPWord/TestHelper.php +++ b/Tests/_inc/TestHelperDOCX.php @@ -4,31 +4,42 @@ namespace PHPWord\Tests; use PHPWord; use DOMDocument; -class TestHelper +class TestHelperDOCX { + static protected $file; + /** * @param \PHPWord $PHPWord - * @return \PHPWord\Tests\Doc + * @return \PHPWord\Tests\Xml_Document */ public static function getDocument(PHPWord $PHPWord) { + self::$file = tempnam(sys_get_temp_dir(), 'PHPWord'); + if(!is_dir(sys_get_temp_dir().'/PHPWord_Unit_Test/')){ + mkdir(sys_get_temp_dir().'/PHPWord_Unit_Test/'); + } + $objWriter = \PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); - $objWriter->save(__DIR__ . '/Tests/_files/test.docx'); + $objWriter->save(self::$file); $zip = new \ZipArchive; - $res = $zip->open(__DIR__ . '/Tests/_files/test.docx'); + $res = $zip->open(self::$file); if ($res === true) { - $zip->extractTo(__DIR__ . '/Tests/_files/test/'); + $zip->extractTo(sys_get_temp_dir().'/PHPWord_Unit_Test/'); $zip->close(); } - return new Doc(__DIR__ . '/Tests/_files/test/'); + return new Xml_Document(sys_get_temp_dir().'/PHPWord_Unit_Test/'); } public static function clear() { - unlink(__DIR__ . '/Tests/_files/test.docx'); - self::deleteDir(__DIR__ . '/Tests/_files/test/'); + if(file_exists(self::$file)){ + unlink(self::$file); + } + if(is_dir(sys_get_temp_dir().'/PHPWord_Unit_Test/')){ + self::deleteDir(sys_get_temp_dir().'/PHPWord_Unit_Test/'); + } } /** @@ -50,7 +61,7 @@ class TestHelper } } -class Doc +class Xml_Document { /** @var string $path */ private $path; diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php new file mode 100644 index 00000000..554dc38f --- /dev/null +++ b/Tests/bootstrap.php @@ -0,0 +1,14 @@ +=5.3.0", "ext-xml": "*" }, + "require-dev": { + "phpunit/phpunit": "3.7.28" + }, "recommend": { "ext-zip": "*", "ext-gd2": "*" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index edb893a7..e57799ce 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,6 +1,6 @@ - - ./test/PHPWord/ + + ./Tests/PHPWord/ - \ No newline at end of file + + + ../Classes + + + diff --git a/samples/Sample_03_Sections.php b/samples/Sample_03_Sections.php new file mode 100644 index 00000000..d2231dfa --- /dev/null +++ b/samples/Sample_03_Sections.php @@ -0,0 +1,55 @@ +'); +} + +require_once '../Classes/PHPWord.php'; + +// New Word Document +echo date('H:i:s') , ' Create new PHPWord object' , EOL; +$PHPWord = new PHPWord(); + +// New portrait section +$section = $PHPWord->createSection(array('borderColor' => '00FF00', 'borderSize' => 12)); +$section->addText('I am placed on a default section.'); + +// New landscape section +$section = $PHPWord->createSection(array('orientation' => 'landscape')); +$section->addText('I am placed on a landscape section. Every page starting from this section will be landscape style.'); +$section->addPageBreak(); +$section->addPageBreak(); + +// New portrait section +$section = $PHPWord->createSection(array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600)); +$section->addText('This section uses other margins.'); + +// New portrait section with Header & Footer +$section = $PHPWord->createSection(array('marginLeft' => 200, 'marginRight' => 200, 'marginTop' => 200, 'marginBottom' => 200, 'headerHeight' => 50, 'footerHeight' => 50,)); +$section->addText('This section and we play with header/footer height.'); +$section->createHeader()->addText('Header'); +$section->createFooter()->addText('Footer'); + +// Save File +echo date('H:i:s') , ' Write to Word2007 format' , EOL; +$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); +$objWriter->save(str_replace('.php', '.docx', __FILE__)); + +/*echo date('H:i:s') , ' Write to OpenDocumentText format' , EOL; +$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'ODText'); +$objWriter->save(str_replace('.php', '.odt', __FILE__)); + +echo date('H:i:s') , ' Write to RTF format' , EOL; +$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'RTF'); +$objWriter->save(str_replace('.php', '.rtf', __FILE__));*/ + + +// Echo memory peak usage +echo date('H:i:s') , ' Peak memory usage: ' , (memory_get_peak_usage(true) / 1024 / 1024) , ' MB' , EOL; + +// Echo done +echo date('H:i:s') , ' Done writing file' , EOL; diff --git a/samples/Sample_04_Textrun.php b/samples/Sample_04_Textrun.php new file mode 100644 index 00000000..80ad2d3c --- /dev/null +++ b/samples/Sample_04_Textrun.php @@ -0,0 +1,61 @@ +'); +} + +require_once '../Classes/PHPWord.php'; + +// New Word Document +echo date('H:i:s') , ' Create new PHPWord object' , EOL; +$PHPWord = new PHPWord(); + + +// Ads styles +$PHPWord->addParagraphStyle('pStyle', array('spacing'=>100)); +$PHPWord->addFontStyle('BoldText', array('bold'=>true)); +$PHPWord->addFontStyle('ColoredText', array('color'=>'FF8080')); +$PHPWord->addLinkStyle('NLink', array('color'=>'0000FF', 'underline'=>PHPWord_Style_Font::UNDERLINE_SINGLE)); + +// New portrait section +$section = $PHPWord->createSection(); + +// Add text run +$textrun = $section->createTextRun('pStyle'); + +$textrun->addText('Each textrun can contain native text, link elements or an image.'); +$textrun->addText(' No break is placed after adding an element.', 'BoldText'); +$textrun->addText(' All elements are placed inside a paragraph with the optionally given p-Style.', 'ColoredText'); +$textrun->addText(' Sample Link: '); +$textrun->addLink('http://www.google.com', null, 'NLink'); +$textrun->addText(' Sample Image: '); +$textrun->addImage('old/_earth.jpg', array('width'=>18, 'height'=>18)); +$textrun->addText(' Here is some more text. '); + +// Save File +echo date('H:i:s') , ' Write to Word2007 format' , EOL; +$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); +$objWriter->save(str_replace('.php', '.docx', __FILE__)); + +/* Text Run is not currently supported for ODText +echo date('H:i:s') , ' Write to OpenDocumentText format' , EOL; +$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'ODText'); +$objWriter->save(str_replace('.php', '.odt', __FILE__)); +*/ + +/* Text Run is not currently supported for RTF +echo date('H:i:s') , ' Write to RTF format' , EOL; +$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'RTF'); +$objWriter->save(str_replace('.php', '.rtf', __FILE__)); +*/ + +// Echo memory peak usage +echo date('H:i:s') , ' Peak memory usage: ' , (memory_get_peak_usage(true) / 1024 / 1024) , ' MB' , EOL; + +// Echo done +echo date('H:i:s') , ' Done writing file' , EOL; \ No newline at end of file diff --git a/test/PHPWord/Tests/AutoloaderTest.php b/test/PHPWord/Tests/AutoloaderTest.php deleted file mode 100644 index cdfcf68e..00000000 --- a/test/PHPWord/Tests/AutoloaderTest.php +++ /dev/null @@ -1,14 +0,0 @@ -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'); - } -} \ No newline at end of file diff --git a/test/PHPWord/Tests/ImageTest.php b/test/PHPWord/Tests/ImageTest.php deleted file mode 100755 index 81b24677..00000000 --- a/test/PHPWord/Tests/ImageTest.php +++ /dev/null @@ -1,36 +0,0 @@ -createSection(12240, 15840, 0, 0, 0, 0); - - $section->addImage( - __DIR__ . '/_files/images/earth.jpg', - array( - 'marginTop' => -1, - 'marginLeft' => -1, - 'wrappingStyle' => 'behind' - ) - ); - - $doc = TestHelper::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); - } -} \ No newline at end of file diff --git a/test/bootstrap.php b/test/bootstrap.php deleted file mode 100755 index b03b68ce..00000000 --- a/test/bootstrap.php +++ /dev/null @@ -1,8 +0,0 @@ -