Skip to content

Commit

Permalink
Merge branch 'develop' into feature/EnablePasswordProtection
Browse files Browse the repository at this point in the history
  • Loading branch information
troosan authored Dec 4, 2017
2 parents 2e56251 + 86115b9 commit cfc89b7
Show file tree
Hide file tree
Showing 39 changed files with 253 additions and 86 deletions.
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Change Log
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/).

v0.14.0 (?? ???? 2017)
v0.14.0 (?? Dec 2017)
----------------------
This release fixes several bugs and adds some new features.
This is the last version to support PHP 5.3
Expand All @@ -18,13 +18,15 @@ This is the last version to support PHP 5.3
- Support for Comments - @troosan #1067
- Support for paragraph textAlignment - @troosan #1165
- Add support for HTML underline tag <u> in addHtml - @zNightFalLz #1186
- Allow to change cell width unit - guillaume-ro-fr #986
- Allow to change cell width unit - @guillaume-ro-fr #986
- Allow to change the line height rule @troosan
- Implement PageBreak for odt writer @cookiekiller #863 #824
- Allow to force an update of all fields on opening a document - @troosan #951

### Fixed
- Loosen dependency to Zend
- Images are not being printed when generating PDF - @hubertinio #1074 #431
- Fixed some PHP 7 warnings - @ likeuntomurphy #927
- Fixed some PHP 7 warnings - @likeuntomurphy #927
- Fixed Word 97 reader - @alsofronie @Benpxpx @mario-rivera #912 #920 #892
- Fixed image loading over https - @troosan #988
- Impossibility to set different even and odd page headers - @troosan #981
Expand All @@ -39,6 +41,9 @@ This is the last version to support PHP 5.3
- Fix incorrect image size between windows and mac - @bskrtich #874
- Fix adding HTML table to document - @mogilvie @arivanbastos #324

###Deprecated
- PhpWord->getProtection(), get it from the settings instead PhpWord->getSettings()->getDocumentProtection();

v0.13.0 (31 July 2016)
-------------------
This release brings several improvements in `TemplateProcessor`, automatic output escaping feature for OOXML, ODF, HTML, and RTF (turned off, by default).
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,18 @@ PHPWord requires the following:
## Installation

PHPWord is installed via [Composer](https://getcomposer.org/).
You just need to [add dependency](https://getcomposer.org/doc/04-schema.md#package-links>) on PHPWord into your package.
To [add a dependency](https://getcomposer.org/doc/04-schema.md#package-links>) to PHPWord in your project, either

Example:
Run the following to use the latest stable version
```sh
composer require phpoffice/phpword
```
or if you want the latest master version
```sh
composer require phpoffice/phpword:dev-master
```

You can of course also manually edit your composer.json file
```json
{
"require": {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"php": ">=5.3.3",
"ext-xml": "*",
"zendframework/zend-escaper": "^2.2",
"zendframework/zend-stdlib": "^2.2",
"zendframework/zend-stdlib": "^2.2 || ^3.0",
"phpoffice/common": "^0.2"
},
"require-dev": {
Expand Down
28 changes: 28 additions & 0 deletions docs/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Issue tracker is **ONLY** used for reporting bugs. NO NEW FEATURE ACCEPTED! Use [stackoverflow](https://stackoverflow.com/questions/tagged/phpword) for supporting issues.

# Expected Behavior

Please describe the behavior you are expecting.

# Current Behavior

What is the current behavior?

# Failure Information

Please help provide information about the failure.

## How to Reproduce

Please provide a code sample that reproduces the issue.

```php
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$section->...
```

## Context

* PHP version:
* PHPWord version: 0.14
12 changes: 12 additions & 0 deletions docs/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context.

Fixes # (issue)

# Checklist:

- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have run phpunit, phpcs, php-cs-fixer, phpmd
- [ ] The new code is covered by unit tests
- [ ] I have update the documentation to describe the changes
2 changes: 1 addition & 1 deletion docs/elements.rst
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ Your TOC can only be generated if you have add at least one title (See "Titles")

Options for ``$tocStyle``:

- ``tabLeader``. Fill type between the title text and the page number. Use the defined constants in PHPWord\\Style\\TOC.
- ``tabLeader``. Fill type between the title text and the page number. Use the defined constants in ``\PhpOffice\PhpWord\Style\TOC``.
- ``tabPos``. The position of the tab where the page number appears in twips.
- ``indent``. The indent factor of the titles in twips.

Expand Down
9 changes: 9 additions & 0 deletions docs/general.rst
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,12 @@ The document (or parts of it) can be password protected.
$documentProtection = $phpWord->getSettings()->getDocumentProtection();
$documentProtection->setEditing(DocProtect::READ_ONLY);
$documentProtection->setPassword('myPassword');
Automatically Recalculate Fields on Open
----------------------------------------

To force an update of the fields present in the document, set updateFields to true

.. code-block:: php
$phpWord->getSettings()->setUpdateFields(true);
13 changes: 13 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
includes:
- vendor/phpstan/phpstan/conf/config.level1.neon
parameters:
memory-limit: 200000
autoload_directories:
- tests
autoload_files:
- tests/bootstrap.php
excludes_analyse:
- */pclzip.lib.php
- src/PhpWord/Shared/OLERead.php
- src/PhpWord/Reader/MsDoc.php
- src/PhpWord/Writer/PDF/MPDF.php
8 changes: 7 additions & 1 deletion run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
#!/bin/bash
echo "Running composer update"
composer update

## PHP_CodeSniffer
echo "Running CodeSniffer"
./vendor/bin/phpcs src/ tests/ --standard=PSR2 -n --ignore=src/PhpWord/Shared/PCLZip

## PHP-CS-Fixer
echo "Running CS Fixer"
./vendor/bin/php-cs-fixer fix --diff --verbose --dry-run

## PHP Mess Detector
echo "Running Mess Detector"
./vendor/bin/phpmd src/,tests/ text ./phpmd.xml.dist --exclude pclzip.lib.php

## PHPUnit
./vendor/bin/phpunit -c ./ --no-coverage
echo "Running PHPUnit"
./vendor/bin/phpunit -c ./

1 change: 1 addition & 0 deletions samples/Sample_17_TitleTOC.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// New Word document
echo date('H:i:s'), ' Create new PhpWord object', EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$phpWord->getSettings()->setUpdateFields(true);

// New section
$section = $phpWord->addSection();
Expand Down
4 changes: 1 addition & 3 deletions src/PhpWord/Element/Endnote.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

namespace PhpOffice\PhpWord\Element;

use PhpOffice\PhpWord\Style\Paragraph;

/**
* Endnote element
*
Expand All @@ -38,6 +36,6 @@ class Endnote extends Footnote
*/
public function __construct($paragraphStyle = null)
{
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
parent::__construct($paragraphStyle);
}
}
6 changes: 3 additions & 3 deletions src/PhpWord/Element/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Field extends AbstractElement
/**
* Field text
*
* @var TextRun | string
* @var TextRun|string
*/
protected $text;

Expand All @@ -98,7 +98,7 @@ class Field extends AbstractElement
* @param string $type
* @param array $properties
* @param array $options
* @param TextRun | string $text
* @param TextRun|string|null $text
*/
public function __construct($type = null, $properties = array(), $options = array(), $text = null)
{
Expand Down Expand Up @@ -209,7 +209,7 @@ public function getOptions()
* @param string|TextRun $text
*
* @throws \InvalidArgumentException
* @return string|TextRun
* @return null|string|TextRun
*/
public function setText($text)
{
Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Element/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function __construct($source, $style = null, $watermark = false)
$this->setIsWatermark($watermark);
$this->style = $this->setNewStyle(new ImageStyle(), $style, true);

$this->checkImage($source);
$this->checkImage();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/PhpWord/Element/ListItemRun.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
namespace PhpOffice\PhpWord\Element;

use PhpOffice\PhpWord\Style\ListItem as ListItemStyle;
use PhpOffice\PhpWord\Style\Paragraph;

/**
* List item element
Expand Down Expand Up @@ -61,7 +60,7 @@ public function __construct($depth = 0, $listStyle = null, $paragraphStyle = nul
} else {
$this->style = $this->setNewStyle(new ListItemStyle(), $listStyle, true);
}
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
parent::__construct($paragraphStyle);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Element/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function getFooters()
/**
* Get the footnote properties
*
* @return \PhpOffice\PhpWord\Element\FooterProperties
* @return FootnoteProperties
*/
public function getFootnotePropoperties()
{
Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Element/TrackChange.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TrackChange extends AbstractContainer
/**
* Date
*
* @var DateTime
* @var \DateTime
*/
private $date;

Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Metadata/DocInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public function isCustomPropertySet($propertyName)
* Get a Custom Property Value
*
* @param string $propertyName
* @return string
* @return mixed
*/
public function getCustomPropertyValue($propertyName)
{
Expand Down
23 changes: 23 additions & 0 deletions src/PhpWord/Metadata/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ class Settings
*/
private $themeFontLang;

/**
* Automatically Recalculate Fields on Open
*
* @var bool
*/
private $updateFields = false;

/**
* Radix Point for Field Code Evaluation
*
Expand Down Expand Up @@ -345,6 +352,22 @@ public function setThemeFontLang($themeFontLang)
$this->themeFontLang = $themeFontLang;
}

/**
* @return bool
*/
public function hasUpdateFields()
{
return $this->updateFields;
}

/**
* @param bool $updateFields
*/
public function setUpdateFields($updateFields)
{
$this->updateFields = $updateFields === null ? false : $updateFields;
}

/**
* Returns the Radix Point for Field Code Evaluation
*
Expand Down
6 changes: 3 additions & 3 deletions src/PhpWord/Reader/Word2007/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ protected function setZoom(XMLReader $xmlReader, PhpWord $phpWord, \DOMElement $
protected function setRevisionView(XMLReader $xmlReader, PhpWord $phpWord, \DOMElement $node)
{
$revisionView = new TrackChangesView();
$revisionView->setMarkup($xmlReader->getAttribute('w:markup', $node));
$revisionView->setMarkup(filter_var($xmlReader->getAttribute('w:markup', $node), FILTER_VALIDATE_BOOLEAN));
$revisionView->setComments($xmlReader->getAttribute('w:comments', $node));
$revisionView->setInsDel($xmlReader->getAttribute('w:insDel', $node));
$revisionView->setFormatting($xmlReader->getAttribute('w:formatting', $node));
$revisionView->setInkAnnotations($xmlReader->getAttribute('w:inkAnnotations', $node));
$revisionView->setFormatting(filter_var($xmlReader->getAttribute('w:formatting', $node), FILTER_VALIDATE_BOOLEAN));
$revisionView->setInkAnnotations(filter_var($xmlReader->getAttribute('w:inkAnnotations', $node), FILTER_VALIDATE_BOOLEAN));
$phpWord->getSettings()->setRevisionView($revisionView);
}
}
2 changes: 1 addition & 1 deletion src/PhpWord/Shared/AbstractEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static function values()
/**
* Returns true the value is valid for this enum
*
* @param strign $value
* @param string $value
* @return bool true if value is valid
*/
public static function isValid($value)
Expand Down
4 changes: 2 additions & 2 deletions src/PhpWord/Shared/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private static function parseChildNodes($node, $element, $styles, $data)
{
if ('li' != $node->nodeName) {
$cNodes = $node->childNodes;
if (count($cNodes) > 0) {
if (!empty($cNodes)) {
foreach ($cNodes as $cNode) {
if ($element instanceof AbstractContainer || $element instanceof Table || $element instanceof Row) {
self::parseNode($cNode, $element, $styles, $data);
Expand Down Expand Up @@ -389,7 +389,7 @@ private static function parseList(&$styles, &$data, $argument1)
private static function parseListItem($node, $element, &$styles, $data)
{
$cNodes = $node->childNodes;
if (count($cNodes) > 0) {
if (!empty($cNodes)) {
$text = '';
foreach ($cNodes as $cNode) {
if ($cNode->nodeName == '#text') {
Expand Down
4 changes: 2 additions & 2 deletions src/PhpWord/Shared/PCLZip/pclzip.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3790,7 +3790,7 @@ public function privExtractFileUsingTempFile(&$p_entry, &$p_options)
}

// ----- Write gz file format header
$v_binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($p_entry['compression']), Chr(0x00), time(), Chr(0x00), Chr(3));
$v_binary_data = pack('va1a1Va1a1', 0x8b1f, chr($p_entry['compression']), chr(0x00), time(), chr(0x00), chr(3));
@fwrite($v_dest_file, $v_binary_data, 10);

// ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
Expand Down Expand Up @@ -4383,7 +4383,7 @@ public function privReadEndCentralDir(&$p_central_dir)
//$v_bytes = ($v_bytes << 8) | Ord($v_byte);
// Note we mask the old value down such that once shifted we can never end up with more than a 32bit number
// Otherwise on systems where we have 64bit integers the check below for the magic number will fail.
$v_bytes = (($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte);
$v_bytes = (($v_bytes & 0xFFFFFF) << 8) | ord($v_byte);

// ----- Compare the bytes
if ($v_bytes == 0x504b0506) {
Expand Down
5 changes: 3 additions & 2 deletions src/PhpWord/Shared/ZipArchive.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ public function open($filename, $flags = null)
} else {
$zip = new \PclZip($this->filename);
$this->tempDir = Settings::getTempDir();
$this->numFiles = count($zip->listContent());
$zipContent = $zip->listContent();
$this->numFiles = is_array($zipContent) ? count($zipContent) : 0;
}
$this->zip = $zip;

Expand Down Expand Up @@ -351,7 +352,7 @@ public function pclzipGetFromName($filename)
* Returns the name of an entry using its index (emulate \ZipArchive)
*
* @param int $index
* @return string
* @return string|bool
* @since 0.10.0
*/
public function pclzipGetNameIndex($index)
Expand Down
Loading

0 comments on commit cfc89b7

Please sign in to comment.