first commit

This commit is contained in:
Dave Umrysh
2021-02-26 12:53:56 -07:00
commit dc8b19aade
2373 changed files with 374265 additions and 0 deletions

25
vendor/phpoffice/common/.gitignore vendored Normal file
View File

@@ -0,0 +1,25 @@
.DS_Store
._*
.Spotlight-V100
.Trashes
Thumbs.db
Desktop.ini
.idea
build/
phpunit.xml
composer.phar
vendor
*.settings
*.project
*.buildpath
/samples/results
/phpunit.bat
/todo.txt
/samples/Sample_00_Test.php
/samples/#47
/samples/#70
/samples/#71
/samples/Github_*.*
/samples/#83/*.lnk
/composer.lock

View File

@@ -0,0 +1,24 @@
filter:
excluded_paths: [ 'vendor/*', 'tests/*', 'samples/*' ]
before_commands:
- "composer install --prefer-source --dev"
tools:
php_code_sniffer:
enabled: true
config:
standard: PSR2
php_mess_detector:
enabled: true
config:
ruleset: phpmd.xml.dist
external_code_coverage:
enabled: true
timeout: 900
php_cpd: true
# php_sim: # Temporarily disabled to allow focus on things other than duplicates
# min_mass: 40
php_pdepend: true
php_analyzer: true
sensiolabs_security_checker: true

60
vendor/phpoffice/common/.travis.yml vendored Normal file
View File

@@ -0,0 +1,60 @@
language: php
php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- hhvm
matrix:
allow_failures:
- php: 7.1
- php: 7.2
- php: hhvm
env:
global:
## - secure: "LtlUOzC8FtqgbqUTmU7EU281NSCb58UFdvnz8lelNIDltBdP4eayN/TsgNIePB4jXg2d2R56ZA6j/grhE/md6jdUkulV355H3GrH/hIZmmQ+F9+87agnwLzb9+MJbqXoiE7VvjY3zGIO09G897SUfsfu6JWEcscYFlsH6KcXM6M="
before_script:
## Packages
- sudo apt-get -qq update > /dev/null
- sudo apt-get -qq install graphviz > /dev/null
## Composer
- composer self-update
- composer install --prefer-source --dev
## PHPDocumentor
- mkdir -p build/docs
- mkdir -p build/coverage
script:
## PHP_CodeSniffer
- ./vendor/bin/phpcs src/ tests/ --standard=PSR2 -n
## PHP Copy/Paste Detector
# - ./vendor/bin/phpcpd src/
## PHP Mess Detector
- ./vendor/bin/phpmd src/,tests/ text ./phpmd.xml.dist
## PHPUnit
- ./vendor/bin/phpunit -c ./ --coverage-text --coverage-html ./build/coverage
## PHPLOC
- ./vendor/bin/phploc src/
## PHPDocumentor
- ./vendor/bin/phpdoc -q -d ./src -t ./build/docs --template="responsive-twig"
after_script:
## PHPDocumentor
## - bash .travis_shell_after_success.sh
## Scrutinizer
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml
notifications:
webhooks:
urls:
- https://webhooks.gitter.im/e/e019b92a7793d27e080c
on_success: change # options: [always|never|change] default: always
on_failure: always # options: [always|never|change] default: always
on_start: false # default: false

View File

@@ -0,0 +1,39 @@
#!/bin/bash
echo "--DEBUG--"
echo "TRAVIS_REPO_SLUG: $TRAVIS_REPO_SLUG"
echo "TRAVIS_PHP_VERSION: $TRAVIS_PHP_VERSION"
echo "TRAVIS_PULL_REQUEST: $TRAVIS_PULL_REQUEST"
if [ "$TRAVIS_REPO_SLUG" == "PHPOffice/Common" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_PHP_VERSION" == "5.5" ]; then
echo -e "Publishing PHPDoc...\n"
cp -R build/docs $HOME/docs-latest
cp -R build/coverage $HOME/coverage-latest
cd $HOME
git config --global user.email "travis@travis-ci.org"
git config --global user.name "travis-ci"
git clone --quiet --branch=gh-pages https://${GH_TOKEN}@github.com/PHPOffice/Common gh-pages > /dev/null
cd gh-pages
echo "--DEBUG : Suppression"
git rm -rf ./docs/$TRAVIS_BRANCH
echo "--DEBUG : Dossier"
mkdir -p docs/$TRAVIS_BRANCH
mkdir -p coverage/$TRAVIS_BRANCH
echo "--DEBUG : Copie"
cp -Rf $HOME/docs-latest/* ./docs/$TRAVIS_BRANCH/
cp -Rf $HOME/coverage-latest/* ./coverage/$TRAVIS_BRANCH/
echo "--DEBUG : Git"
git add -f .
git commit -m "PHPDocumentor (Travis Build: $TRAVIS_BUILD_NUMBER - Branch: $TRAVIS_BRANCH)"
git push -fq origin gh-pages > /dev/null
echo -e "Published PHPDoc to gh-pages.\n"
fi

61
vendor/phpoffice/common/CHANGELOG.md vendored Normal file
View File

@@ -0,0 +1,61 @@
# Changelog
## 0.1.0
### Features
- Initial Release
## 0.1.1
### Features
- Added String::chr for suppporting Unicode Characters
## 0.2.0
### Changes
- Renamed String class in Text class for supporting PHP7
## 0.2.1
### Features
- Added XMLReader from PHPWord
## 0.2.2
### BugFix
- Fixed "Class 'PhpOffice\Common\ZipArchive' not found in /src/Common/XMLReader.php on line 54"
## 0.2.3
### Features
- Added missing features for supporting PHPWord
## 0.2.4
### Changes
- XMLWriter : Refactoring for improving performances
## 0.2.5
### Features
- Added Zip Adapters (PclZip & ZipArchive)
## 0.2.6
### Changes
- `\PhpOffice\Common\Text::utf8ToUnicode()` became `public`.
## 0.2.7
### Features
- Added `\PhpOffice\Common\File::fileGetContents()` (with support of zip://)
- Added Support for PHP 7.1
## 0.2.8
### Features
- Added possibility to register namespaces to DOMXpath
- Added Utility to get an Office compatible hash of a password
- Write attribute's value of type float independently of locale
## 0.2.9
- Fix XML Entity injection vulnerability

674
vendor/phpoffice/common/COPYING vendored Normal file

File diff suppressed because it is too large Load Diff

165
vendor/phpoffice/common/COPYING.LESSER vendored Normal file
View File

@@ -0,0 +1,165 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.

15
vendor/phpoffice/common/LICENSE vendored Normal file
View File

@@ -0,0 +1,15 @@
PHPOffice Common, a shared PHP library for PHPOffice Libraries
Copyright (c) 2015-2015 PHPOffice.
PHPOffice Common is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 3 as published by
the Free Software Foundation.
PHPOffice Common is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License version 3 for more details.
You should have received a copy of the GNU Lesser General Public License version 3
along with PHPOffice Common. If not, see <http://www.gnu.org/licenses/>.

33
vendor/phpoffice/common/README.md vendored Normal file
View File

@@ -0,0 +1,33 @@
[![Latest Stable Version](https://poser.pugx.org/phpoffice/common/v/stable.png)](https://packagist.org/packages/phpoffice/common)
[![Build Status](https://travis-ci.org/PHPOffice/Common.svg?branch=master)](https://travis-ci.org/PHPOffice/Common)
[![Code Quality](https://scrutinizer-ci.com/g/PHPOffice/Common/badges/quality-score.png?s=b5997ce59ac2816b4514f3a38de9900f6d492c1d)](https://scrutinizer-ci.com/g/PHPOffice/Common/)
[![Code Coverage](https://scrutinizer-ci.com/g/PHPOffice/Common/badges/coverage.png?s=742a98745725c562955440edc8d2c39d7ff5ae25)](https://scrutinizer-ci.com/g/PHPOffice/Common/)
[![Total Downloads](https://poser.pugx.org/phpoffice/common/downloads.png)](https://packagist.org/packages/phpoffice/common)
[![License](https://poser.pugx.org/phpoffice/common/license.png)](https://packagist.org/packages/phpoffice/common)
[![Join the chat at https://gitter.im/PHPOffice/Common](https://img.shields.io/badge/GITTER-join%20chat-green.svg)](https://gitter.im/PHPOffice/Common)
PHPOffice Common is a library written in pure PHP that provides a set of components for PHPOffice librairies.
PHPOffice Common is an open source project licensed under the terms of [LGPL version 3](https://github.com/PHPOffice/Common/blob/develop/COPYING.LESSER). PHPOffice Common is aimed to be a high quality software product by incorporating [continuous integration](https://travis-ci.org/PHPOffice/Common) and [unit testing](http://phpoffice.github.io/Common/coverage/develop/). You can learn more about PHPPowerPoint by reading the [API Documentation](http://phpoffice.github.io/Common/docs/develop/).
Read more about PHPPowerPoint:
- [Requirements](#requirements)
- [Contributing](#contributing)
- [API Documentation](http://phpoffice.github.io/Common/docs/master/)
### Requirements
PHPOffice Common requires the following:
- PHP 5.3+
## Contributing
We welcome everyone to contribute to PHPOffice Common. Below are some of the things that you can do to contribute:
- Read [our contributing guide](https://github.com/PHPOffice/Common/blob/master/CONTRIBUTING.md)
- [Fork us](https://github.com/PHPOffice/Common/fork) and [request a pull](https://github.com/PHPOffice/Common/pulls) to the [develop](https://github.com/PHPOffice/Common/tree/develop) branch
- Submit [bug reports or feature requests](https://github.com/PHPOffice/Common/issues) to GitHub
- Follow [@PHPOffice](https://twitter.com/PHPOffice) on Twitter

1
vendor/phpoffice/common/VERSION vendored Normal file
View File

@@ -0,0 +1 @@
0.2.9

34
vendor/phpoffice/common/composer.json vendored Normal file
View File

@@ -0,0 +1,34 @@
{
"name": "phpoffice/common",
"description": "PHPOffice Common",
"keywords": ["PHP","Office","Common","component"],
"homepage": "http://phpoffice.github.io",
"type": "library",
"license": "LGPL",
"authors": [
{
"name": "Mark Baker"
},
{
"name": "Franck Lefevre",
"homepage": "http://rootslabs.net"
}
],
"require": {
"php": ">=5.3.0",
"pclzip/pclzip": "^2.8"
},
"require-dev": {
"phpunit/phpunit": "^4.8.36 || ^7.0",
"phpdocumentor/phpdocumentor":"2.*",
"phpmd/phpmd": "2.*",
"sebastian/phpcpd": "2.*",
"phploc/phploc": "2.*",
"squizlabs/php_codesniffer": "2.*"
},
"autoload": {
"psr-4": {
"PhpOffice\\Common\\": "src/Common/"
}
}
}

33
vendor/phpoffice/common/phpmd.xml.dist vendored Normal file
View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8" ?>
<ruleset name="PHPOffice Common PHP Mess Detector Rule Set"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<rule ref="rulesets/naming.xml">
<exclude name="LongVariable" />
</rule>
<rule ref="rulesets/naming.xml/LongVariable">
<properties>
<property name="maximum" value="32" />
</properties>
</rule>
<rule ref="rulesets/design.xml/ExitExpression" />
<rule ref="rulesets/design.xml/EvalExpression" />
<rule ref="rulesets/design.xml/GotoStatement" />
<rule ref="rulesets/design.xml/DepthOfInheritance" />
<rule ref="rulesets/design.xml/CouplingBetweenObjects">
<!-- AbstractContainer needs more coupling (default: 13) -->
<properties>
<property name="minimum" value="20" />
</properties>
</rule>
<rule ref="rulesets/design.xml/NumberOfChildren">
<!-- AbstractStyle needs more children (default: 15) -->
<properties>
<property name="minimum" value="30" />
</properties>
</rule>
<rule ref="rulesets/unusedcode.xml" />
<rule ref="rulesets/controversial.xml" />
</ruleset>

View File

@@ -0,0 +1,24 @@
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="./tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="PhpOffice Common Test Suite">
<directory>./tests/Common</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="./build/coverage" />
<log type="coverage-clover" target="./build/logs/clover.xml" />
</logging>
</phpunit>

View File

@@ -0,0 +1,45 @@
<?php
namespace PhpOffice\Common\Adapter\Zip;
use PclZip;
class PclZipAdapter implements ZipInterface
{
/**
* @var PclZip
*/
protected $oPclZip;
/**
* @var string
*/
protected $tmpDir;
public function open($filename)
{
$this->oPclZip = new PclZip($filename);
$this->tmpDir = sys_get_temp_dir();
return $this;
}
public function close()
{
return $this;
}
public function addFromString($localname, $contents)
{
$pathData = pathinfo($localname);
$hFile = fopen($this->tmpDir.'/'.$pathData['basename'], "wb");
fwrite($hFile, $contents);
fclose($hFile);
$res = $this->oPclZip->add($this->tmpDir.'/'.$pathData['basename'], PCLZIP_OPT_REMOVE_PATH, $this->tmpDir, PCLZIP_OPT_ADD_PATH, $pathData['dirname']);
if ($res == 0) {
throw new \Exception("Error zipping files : " . $this->oPclZip->errorInfo(true));
}
unlink($this->tmpDir.'/'.$pathData['basename']);
return $this;
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace PhpOffice\Common\Adapter\Zip;
use ZipArchive;
class ZipArchiveAdapter implements ZipInterface
{
/**
* @var ZipArchive
*/
protected $oZipArchive;
/**
* @var string
*/
protected $filename;
public function open($filename)
{
$this->filename = $filename;
$this->oZipArchive = new ZipArchive();
if ($this->oZipArchive->open($this->filename, ZipArchive::OVERWRITE) === true) {
return $this;
}
if ($this->oZipArchive->open($this->filename, ZipArchive::CREATE) === true) {
return $this;
}
throw new \Exception("Could not open $this->filename for writing.");
}
public function close()
{
if ($this->oZipArchive->close() === false) {
throw new \Exception("Could not close zip file $this->filename.");
}
return $this;
}
public function addFromString($localname, $contents)
{
if ($this->oZipArchive->addFromString($localname, $contents) === false) {
throw new \Exception("Error zipping files : " . $localname);
}
return $this;
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace PhpOffice\Common\Adapter\Zip;
interface ZipInterface
{
/**
* Open a ZIP file archive
* @param string $filename
* @return $this
* @throws \Exception
*/
public function open($filename);
/**
* Close the active archive (opened or newly created)
* @return $this
* @throws \Exception
*/
public function close();
/**
* Add a file to a ZIP archive using its contents
* @param string $localname The name of the entry to create.
* @param string $contents The contents to use to create the entry. It is used in a binary safe mode.
* @return $this
* @throws \Exception
*/
public function addFromString($localname, $contents);
}

View File

@@ -0,0 +1,54 @@
<?php
/**
* This file is part of PHPOffice Common
*
* PHPOffice Common is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/Common/contributors.
*
* @link https://github.com/PHPOffice/Common
* @copyright 2009-2016 PHPOffice Common contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\Common;
/**
* Autoloader
*/
class Autoloader
{
/** @const string */
const NAMESPACE_PREFIX = 'PhpOffice\\Common\\';
/**
* Register
*
* @return void
*/
public static function register()
{
spl_autoload_register(array(new self, 'autoload'));
}
/**
* Autoload
*
* @param string $class
*/
public static function autoload($class)
{
$prefixLength = strlen(self::NAMESPACE_PREFIX);
if (0 === strncmp(self::NAMESPACE_PREFIX, $class, $prefixLength)) {
$file = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, $prefixLength));
$file = realpath(__DIR__ . (empty($file) ? '' : DIRECTORY_SEPARATOR) . $file . '.php');
if (file_exists($file)) {
/** @noinspection PhpIncludeInspection Dynamic includes */
require_once $file;
}
}
}
}

View File

@@ -0,0 +1,237 @@
<?php
/**
* This file is part of PHPOffice Common
*
* PHPOffice Common is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @link https://github.com/PHPOffice/Common
* @copyright 2009-2016 PHPOffice Common contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\Common;
/**
* \PhpOffice\Common\Drawing
*/
class Drawing
{
const DPI_96 = 96;
/**
* Convert pixels to EMU
*
* @param int $pValue Value in pixels
* @return int
*/
public static function pixelsToEmu($pValue = 0)
{
return round($pValue * 9525);
}
/**
* Convert EMU to pixels
*
* @param int $pValue Value in EMU
* @return int
*/
public static function emuToPixels($pValue = 0)
{
if ($pValue == 0) {
return 0;
}
return round($pValue / 9525);
}
/**
* Convert pixels to points
*
* @param int $pValue Value in pixels
* @return float
*/
public static function pixelsToPoints($pValue = 0)
{
return $pValue * 0.67777777;
}
/**
* Convert points width to centimeters
*
* @param int $pValue Value in points
* @return float
*/
public static function pointsToCentimeters($pValue = 0)
{
if ($pValue == 0) {
return 0;
}
return ((($pValue * 1.333333333) / self::DPI_96) * 2.54);
}
/**
* Convert points width to pixels
*
* @param int $pValue Value in points
* @return float
*/
public static function pointsToPixels($pValue = 0)
{
if ($pValue == 0) {
return 0;
}
return $pValue * 1.333333333;
}
/**
* Convert pixels to centimeters
*
* @param int $pValue Value in pixels
* @return float
*/
public static function pixelsToCentimeters($pValue = 0)
{
//return $pValue * 0.028;
return (($pValue / self::DPI_96) * 2.54);
}
/**
* Convert centimeters width to pixels
*
* @param int $pValue Value in centimeters
* @return float
*/
public static function centimetersToPixels($pValue = 0)
{
if ($pValue == 0) {
return 0;
}
return ($pValue / 2.54) * self::DPI_96;
}
/**
* Convert degrees to angle
*
* @param int $pValue Degrees
* @return int
*/
public static function degreesToAngle($pValue = 0)
{
return (int) round($pValue * 60000);
}
/**
* Convert angle to degrees
*
* @param int $pValue Angle
* @return int
*/
public static function angleToDegrees($pValue = 0)
{
if ($pValue == 0) {
return 0;
}
return round($pValue / 60000);
}
/**
* Convert centimeters width to twips
*
* @param integer $pValue
* @return float
*/
public static function centimetersToTwips($pValue = 0)
{
if ($pValue == 0) {
return 0;
}
return $pValue * 566.928;
}
/**
* Convert twips width to centimeters
*
* @param integer $pValue
* @return float
*/
public static function twipsToCentimeters($pValue = 0)
{
if ($pValue == 0) {
return 0;
}
return $pValue / 566.928;
}
/**
* Convert inches width to twips
*
* @param integer $pValue
* @return float
*/
public static function inchesToTwips($pValue = 0)
{
if ($pValue == 0) {
return 0;
}
return $pValue * 1440;
}
/**
* Convert twips width to inches
*
* @param integer $pValue
* @return float
*/
public static function twipsToInches($pValue = 0)
{
if ($pValue == 0) {
return 0;
}
return $pValue / 1440;
}
/**
* Convert twips width to pixels
*
* @param integer $pValue
* @return float
*/
public static function twipsToPixels($pValue = 0)
{
if ($pValue == 0) {
return 0;
}
return round($pValue / 15.873984);
}
/**
* Convert HTML hexadecimal to RGB
*
* @param string $pValue HTML Color in hexadecimal
* @return array Value in RGB
*/
public static function htmlToRGB($pValue)
{
if ($pValue[0] == '#') {
$pValue = substr($pValue, 1);
}
if (strlen($pValue) == 6) {
list($colorR, $colorG, $colorB) = array($pValue[0] . $pValue[1], $pValue[2] . $pValue[3], $pValue[4] . $pValue[5]);
} elseif (strlen($pValue) == 3) {
list($colorR, $colorG, $colorB) = array($pValue[0] . $pValue[0], $pValue[1] . $pValue[1], $pValue[2] . $pValue[2]);
} else {
return false;
}
$colorR = hexdec($colorR);
$colorG = hexdec($colorG);
$colorB = hexdec($colorB);
return array($colorR, $colorG, $colorB);
}
}

View File

@@ -0,0 +1,112 @@
<?php
/**
* This file is part of PHPOffice Common
*
* PHPOffice Common is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @link https://github.com/PHPOffice/Common
* @copyright 2009-2016 PHPOffice Common contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\Common;
/**
* Drawing
*/
class File
{
/**
* Verify if a file exists
*
* @param string $pFilename Filename
* @return bool
*/
public static function fileExists($pFilename)
{
// Sick construction, but it seems that
// file_exists returns strange values when
// doing the original file_exists on ZIP archives...
if (strtolower(substr($pFilename, 0, 3)) == 'zip') {
// Open ZIP file and verify if the file exists
$zipFile = substr($pFilename, 6, strpos($pFilename, '#') - 6);
$archiveFile = substr($pFilename, strpos($pFilename, '#') + 1);
$zip = new \ZipArchive();
if ($zip->open($zipFile) === true) {
$returnValue = ($zip->getFromName($archiveFile) !== false);
$zip->close();
return $returnValue;
}
return false;
}
// Regular file_exists
return file_exists($pFilename);
}
/**
* Returns the content of a file
*
* @param string $pFilename Filename
* @return string
*/
public static function fileGetContents($pFilename)
{
if (!self::fileExists($pFilename)) {
return false;
}
if (strtolower(substr($pFilename, 0, 3)) == 'zip') {
// Open ZIP file and verify if the file exists
$zipFile = substr($pFilename, 6, strpos($pFilename, '#') - 6);
$archiveFile = substr($pFilename, strpos($pFilename, '#') + 1);
$zip = new \ZipArchive();
if ($zip->open($zipFile) === true) {
$returnValue = $zip->getFromName($archiveFile);
$zip->close();
return $returnValue;
}
return false;
}
// Regular file contents
return file_get_contents($pFilename);
}
/**
* Returns canonicalized absolute pathname, also for ZIP archives
*
* @param string $pFilename
* @return string
*/
public static function realpath($pFilename)
{
// Try using realpath()
$returnValue = realpath($pFilename);
// Found something?
if ($returnValue == '' || is_null($returnValue)) {
$pathArray = explode('/', $pFilename);
while (in_array('..', $pathArray) && $pathArray[0] != '..') {
$numPathArray = count($pathArray);
for ($i = 0; $i < $numPathArray; ++$i) {
if ($pathArray[$i] == '..' && $i > 0) {
unset($pathArray[$i]);
unset($pathArray[$i - 1]);
break;
}
}
}
$returnValue = implode('/', $pathArray);
}
// Return
return $returnValue;
}
}

View File

@@ -0,0 +1,100 @@
<?php
/**
* This file is part of PHPOffice Common
*
* PHPOffice Common is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/Common/contributors.
*
* @link https://github.com/PHPOffice/Common
* @copyright 2009-2016 PHPOffice Common contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\Common;
/**
* Font
*/
class Font
{
/**
* Calculate an (approximate) pixel size, based on a font points size
*
* @param int $fontSizeInPoints Font size (in points)
* @return int Font size (in pixels)
*/
public static function fontSizeToPixels($fontSizeInPoints = 12)
{
return ((16 / 12) * $fontSizeInPoints);
}
/**
* Calculate an (approximate) pixel size, based on inch size
*
* @param int $sizeInInch Font size (in inch)
* @return int Size (in pixels)
*/
public static function inchSizeToPixels($sizeInInch = 1)
{
return ($sizeInInch * 96);
}
/**
* Calculate an (approximate) pixel size, based on centimeter size
*
* @param int $sizeInCm Font size (in centimeters)
* @return int Size (in pixels)
*/
public static function centimeterSizeToPixels($sizeInCm = 1)
{
return ($sizeInCm * 37.795275591);
}
/**
* Convert centimeter to twip
*
* @param int $sizeInCm
* @return double
*/
public static function centimeterSizeToTwips($sizeInCm = 1)
{
return $sizeInCm / 2.54 * 1440;
}
/**
* Convert inch to twip
*
* @param int $sizeInInch
* @return double
*/
public static function inchSizeToTwips($sizeInInch = 1)
{
return $sizeInInch * 1440;
}
/**
* Convert pixel to twip
*
* @param int $sizeInPixel
* @return double
*/
public static function pixelSizeToTwips($sizeInPixel = 1)
{
return $sizeInPixel / 96 * 1440;
}
/**
* Calculate twip based on point size, used mainly for paragraph spacing
*
* @param integer $sizeInPoint Size in point
* @return integer Size (in twips)
*/
public static function pointSizeToTwips($sizeInPoint = 1)
{
return $sizeInPoint / 72 * 1440;
}
}

View File

@@ -0,0 +1,320 @@
<?php
/**
* This file is part of PHPOffice Common
*
* PHPOffice Common is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/Common/contributors.
*
* @link https://github.com/PHPOffice/Common
* @copyright 2009-2016 PHPOffice Common contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\Common\Microsoft;
if (!defined('IDENTIFIER_OLE')) {
define('IDENTIFIER_OLE', pack('CCCCCCCC', 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1));
}
class OLERead
{
private $data = '';
// OLE identifier
const IDENTIFIER_OLE = IDENTIFIER_OLE;
// Size of a sector = 512 bytes
const BIG_BLOCK_SIZE = 0x200;
// Size of a short sector = 64 bytes
const SMALL_BLOCK_SIZE = 0x40;
// Size of a directory entry always = 128 bytes
const PROPERTY_STORAGE_BLOCK_SIZE = 0x80;
// Minimum size of a standard stream = 4096 bytes, streams smaller than this are stored as short streams
const SMALL_BLOCK_THRESHOLD = 0x1000;
// header offsets
const NUM_BIG_BLOCK_DEPOT_BLOCKS_POS = 0x2c;
const ROOT_START_BLOCK_POS = 0x30;
const SMALL_BLOCK_DEPOT_BLOCK_POS = 0x3c;
const EXTENSION_BLOCK_POS = 0x44;
const NUM_EXTENSION_BLOCK_POS = 0x48;
const BIG_BLOCK_DEPOT_BLOCKS_POS = 0x4c;
// property storage offsets (directory offsets)
const SIZE_OF_NAME_POS = 0x40;
const TYPE_POS = 0x42;
const START_BLOCK_POS = 0x74;
const SIZE_POS = 0x78;
public $summaryInformation = null;
public $docSummaryInfos = null;
public $powerpointDocument = null;
public $currentUser = null;
public $pictures = null;
public $rootEntry = null;
public $props = array();
public $smallBlockChain = null;
public $bigBlockChain = null;
public $entry = null;
/**
* Read the file
*
* @param $sFileName string Filename
* @throws \Exception
*/
public function read($sFileName)
{
// Check if file exists and is readable
if (!is_readable($sFileName)) {
throw new \Exception("Could not open " . $sFileName . " for reading! File does not exist, or it is not readable.");
}
// Get the file identifier
// Don't bother reading the whole file until we know it's a valid OLE file
$this->data = file_get_contents($sFileName, false, null, 0, 8);
// Check OLE identifier
if ($this->data != self::IDENTIFIER_OLE) {
throw new \Exception('The filename ' . $sFileName . ' is not recognised as an OLE file');
}
// Get the file data
$this->data = file_get_contents($sFileName);
// Total number of sectors used for the SAT
$numBigBlkDepotBlks = self::getInt4d($this->data, self::NUM_BIG_BLOCK_DEPOT_BLOCKS_POS);
// SecID of the first sector of the directory stream
$rootStartBlock = self::getInt4d($this->data, self::ROOT_START_BLOCK_POS);
// SecID of the first sector of the SSAT (or -2 if not extant)
$sbdStartBlock = self::getInt4d($this->data, self::SMALL_BLOCK_DEPOT_BLOCK_POS);
// SecID of the first sector of the MSAT (or -2 if no additional sectors are used)
$extensionBlock = self::getInt4d($this->data, self::EXTENSION_BLOCK_POS);
// Total number of sectors used by MSAT
$numExtensionBlocks = self::getInt4d($this->data, self::NUM_EXTENSION_BLOCK_POS);
$bigBlockDepotBlocks = array();
$pos = self::BIG_BLOCK_DEPOT_BLOCKS_POS;
$bbdBlocks = $numBigBlkDepotBlks;
if ($numExtensionBlocks != 0) {
$bbdBlocks = (self::BIG_BLOCK_SIZE - self::BIG_BLOCK_DEPOT_BLOCKS_POS)/4;
}
for ($i = 0; $i < $bbdBlocks; ++$i) {
$bigBlockDepotBlocks[$i] = self::getInt4d($this->data, $pos);
$pos += 4;
}
for ($j = 0; $j < $numExtensionBlocks; ++$j) {
$pos = ($extensionBlock + 1) * self::BIG_BLOCK_SIZE;
$blocksToRead = min($numBigBlkDepotBlks - $bbdBlocks, self::BIG_BLOCK_SIZE / 4 - 1);
for ($i = $bbdBlocks; $i < $bbdBlocks + $blocksToRead; ++$i) {
$bigBlockDepotBlocks[$i] = self::getInt4d($this->data, $pos);
$pos += 4;
}
$bbdBlocks += $blocksToRead;
if ($bbdBlocks < $numBigBlkDepotBlks) {
$extensionBlock = self::getInt4d($this->data, $pos);
}
}
$this->bigBlockChain = '';
$bbs = self::BIG_BLOCK_SIZE / 4;
for ($i = 0; $i < $numBigBlkDepotBlks; ++$i) {
$pos = ($bigBlockDepotBlocks[$i] + 1) * self::BIG_BLOCK_SIZE;
$this->bigBlockChain .= substr($this->data, $pos, 4*$bbs);
$pos += 4*$bbs;
}
$sbdBlock = $sbdStartBlock;
$this->smallBlockChain = '';
while ($sbdBlock != -2) {
$pos = ($sbdBlock + 1) * self::BIG_BLOCK_SIZE;
$this->smallBlockChain .= substr($this->data, $pos, 4*$bbs);
$pos += 4*$bbs;
$sbdBlock = self::getInt4d($this->bigBlockChain, $sbdBlock*4);
}
// read the directory stream
$block = $rootStartBlock;
$this->entry = $this->readData($block);
$this->readPropertySets();
}
/**
* Extract binary stream data
*
* @return string
*/
public function getStream($stream)
{
if ($stream === null) {
return null;
}
$streamData = '';
if ($this->props[$stream]['size'] < self::SMALL_BLOCK_THRESHOLD) {
$rootdata = $this->readData($this->props[$this->rootEntry]['startBlock']);
$block = $this->props[$stream]['startBlock'];
while ($block != -2) {
$pos = $block * self::SMALL_BLOCK_SIZE;
$streamData .= substr($rootdata, $pos, self::SMALL_BLOCK_SIZE);
$block = self::getInt4d($this->smallBlockChain, $block*4);
}
return $streamData;
}
$numBlocks = $this->props[$stream]['size'] / self::BIG_BLOCK_SIZE;
if ($this->props[$stream]['size'] % self::BIG_BLOCK_SIZE != 0) {
++$numBlocks;
}
if ($numBlocks == 0) {
return '';
}
$block = $this->props[$stream]['startBlock'];
while ($block != -2) {
$pos = ($block + 1) * self::BIG_BLOCK_SIZE;
$streamData .= substr($this->data, $pos, self::BIG_BLOCK_SIZE);
$block = self::getInt4d($this->bigBlockChain, $block*4);
}
return $streamData;
}
/**
* Read a standard stream (by joining sectors using information from SAT)
*
* @param int $blID Sector ID where the stream starts
* @return string Data for standard stream
*/
private function readData($blID)
{
$block = $blID;
$data = '';
while ($block != -2) {
$pos = ($block + 1) * self::BIG_BLOCK_SIZE;
$data .= substr($this->data, $pos, self::BIG_BLOCK_SIZE);
$block = self::getInt4d($this->bigBlockChain, $block*4);
}
return $data;
}
/**
* Read entries in the directory stream.
*/
private function readPropertySets()
{
$offset = 0;
// loop through entires, each entry is 128 bytes
$entryLen = strlen($this->entry);
while ($offset < $entryLen) {
// entry data (128 bytes)
$data = substr($this->entry, $offset, self::PROPERTY_STORAGE_BLOCK_SIZE);
// size in bytes of name
$nameSize = ord($data[self::SIZE_OF_NAME_POS]) | (ord($data[self::SIZE_OF_NAME_POS+1]) << 8);
// type of entry
$type = ord($data[self::TYPE_POS]);
// sectorID of first sector or short sector, if this entry refers to a stream (the case with workbook)
// sectorID of first sector of the short-stream container stream, if this entry is root entry
$startBlock = self::getInt4d($data, self::START_BLOCK_POS);
$size = self::getInt4d($data, self::SIZE_POS);
$name = str_replace("\x00", "", substr($data, 0, $nameSize));
if ($size > 0) {
$this->props[] = array (
'name' => $name,
'type' => $type,
'startBlock' => $startBlock,
'size' => $size);
// tmp helper to simplify checks
$upName = strtoupper($name);
switch ($upName) {
case 'ROOT ENTRY':
case 'R':
$this->rootEntry = count($this->props) - 1;
break;
case chr(1).'COMPOBJ':
break;
case chr(1).'OLE':
break;
case chr(5).'SUMMARYINFORMATION':
$this->summaryInformation = count($this->props) - 1;
break;
case chr(5).'DOCUMENTSUMMARYINFORMATION':
$this->docSummaryInfos = count($this->props) - 1;
break;
case 'CURRENT USER':
$this->currentUser = count($this->props) - 1;
break;
case 'PICTURES':
$this->pictures = count($this->props) - 1;
break;
case 'POWERPOINT DOCUMENT':
$this->powerpointDocument = count($this->props) - 1;
break;
default:
throw new \Exception('OLE Block Not defined: $upName : '.$upName. ' - $name : "'.$name.'"');
}
}
$offset += self::PROPERTY_STORAGE_BLOCK_SIZE;
}
}
/**
* Read 4 bytes of data at specified position
*
* @param string $data
* @param int $pos
* @return int
*/
private static function getInt4d($data, $pos)
{
// FIX: represent numbers correctly on 64-bit system
// http://sourceforge.net/tracker/index.php?func=detail&aid=1487372&group_id=99160&atid=623334
// Hacked by Andreas Rehm 2006 to ensure correct result of the <<24 block on 32 and 64bit systems
$or24 = ord($data[$pos + 3]);
if ($or24 >= 128) {
// negative number
$ord24 = -abs((256 - $or24) << 24);
} else {
$ord24 = ($or24 & 127) << 24;
}
return ord($data[$pos]) | (ord($data[$pos + 1]) << 8) | (ord($data[$pos + 2]) << 16) | $ord24;
}
}

View File

@@ -0,0 +1,234 @@
<?php
/**
* This file is part of PHPOffice Common
*
* PHPOffice Common is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/Common/contributors.
*
* @link https://github.com/PHPOffice/Common
* @copyright 2009-2016 PHPOffice Common contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\Common\Microsoft;
/**
* Password encoder for microsoft office applications
*/
class PasswordEncoder
{
const ALGORITHM_MD2 = 'MD2';
const ALGORITHM_MD4 = 'MD4';
const ALGORITHM_MD5 = 'MD5';
const ALGORITHM_SHA_1 = 'SHA-1';
const ALGORITHM_SHA_256 = 'SHA-256';
const ALGORITHM_SHA_384 = 'SHA-384';
const ALGORITHM_SHA_512 = 'SHA-512';
const ALGORITHM_RIPEMD = 'RIPEMD';
const ALGORITHM_RIPEMD_160 = 'RIPEMD-160';
const ALGORITHM_MAC = 'MAC';
const ALGORITHM_HMAC = 'HMAC';
/**
* Mapping between algorithm name and algorithm ID
*
* @var array
* @see https://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.writeprotection.cryptographicalgorithmsid(v=office.14).aspx
*/
private static $algorithmMapping = array(
self::ALGORITHM_MD2 => array(1, 'md2'),
self::ALGORITHM_MD4 => array(2, 'md4'),
self::ALGORITHM_MD5 => array(3, 'md5'),
self::ALGORITHM_SHA_1 => array(4, 'sha1'),
self::ALGORITHM_MAC => array(5, ''), // 'mac' -> not possible with hash()
self::ALGORITHM_RIPEMD => array(6, 'ripemd'),
self::ALGORITHM_RIPEMD_160 => array(7, 'ripemd160'),
self::ALGORITHM_HMAC => array(9, ''), //'hmac' -> not possible with hash()
self::ALGORITHM_SHA_256 => array(12, 'sha256'),
self::ALGORITHM_SHA_384 => array(13, 'sha384'),
self::ALGORITHM_SHA_512 => array(14, 'sha512'),
);
private static $initialCodeArray = array(
0xE1F0,
0x1D0F,
0xCC9C,
0x84C0,
0x110C,
0x0E10,
0xF1CE,
0x313E,
0x1872,
0xE139,
0xD40F,
0x84F9,
0x280C,
0xA96A,
0x4EC3,
);
private static $encryptionMatrix = array(
array(0xAEFC, 0x4DD9, 0x9BB2, 0x2745, 0x4E8A, 0x9D14, 0x2A09),
array(0x7B61, 0xF6C2, 0xFDA5, 0xEB6B, 0xC6F7, 0x9DCF, 0x2BBF),
array(0x4563, 0x8AC6, 0x05AD, 0x0B5A, 0x16B4, 0x2D68, 0x5AD0),
array(0x0375, 0x06EA, 0x0DD4, 0x1BA8, 0x3750, 0x6EA0, 0xDD40),
array(0xD849, 0xA0B3, 0x5147, 0xA28E, 0x553D, 0xAA7A, 0x44D5),
array(0x6F45, 0xDE8A, 0xAD35, 0x4A4B, 0x9496, 0x390D, 0x721A),
array(0xEB23, 0xC667, 0x9CEF, 0x29FF, 0x53FE, 0xA7FC, 0x5FD9),
array(0x47D3, 0x8FA6, 0x0F6D, 0x1EDA, 0x3DB4, 0x7B68, 0xF6D0),
array(0xB861, 0x60E3, 0xC1C6, 0x93AD, 0x377B, 0x6EF6, 0xDDEC),
array(0x45A0, 0x8B40, 0x06A1, 0x0D42, 0x1A84, 0x3508, 0x6A10),
array(0xAA51, 0x4483, 0x8906, 0x022D, 0x045A, 0x08B4, 0x1168),
array(0x76B4, 0xED68, 0xCAF1, 0x85C3, 0x1BA7, 0x374E, 0x6E9C),
array(0x3730, 0x6E60, 0xDCC0, 0xA9A1, 0x4363, 0x86C6, 0x1DAD),
array(0x3331, 0x6662, 0xCCC4, 0x89A9, 0x0373, 0x06E6, 0x0DCC),
array(0x1021, 0x2042, 0x4084, 0x8108, 0x1231, 0x2462, 0x48C4),
);
private static $passwordMaxLength = 15;
/**
* Create a hashed password that MS Word will be able to work with
* @see https://blogs.msdn.microsoft.com/vsod/2010/04/05/how-to-set-the-editing-restrictions-in-word-using-open-xml-sdk-2-0/
*
* @param string $password
* @param string $algorithmName
* @param string $salt
* @param int $spinCount
* @return string
*/
public static function hashPassword($password, $algorithmName = self::ALGORITHM_SHA_1, $salt = null, $spinCount = 10000)
{
$origEncoding = mb_internal_encoding();
mb_internal_encoding('UTF-8');
$password = mb_substr($password, 0, min(self::$passwordMaxLength, mb_strlen($password)));
// Get the single-byte values by iterating through the Unicode characters of the truncated password.
// For each character, if the low byte is not equal to 0, take it. Otherwise, take the high byte.
$passUtf8 = mb_convert_encoding($password, 'UCS-2LE', 'UTF-8');
$byteChars = array();
for ($i = 0; $i < mb_strlen($password); $i++) {
$byteChars[$i] = ord(substr($passUtf8, $i * 2, 1));
if ($byteChars[$i] == 0) {
$byteChars[$i] = ord(substr($passUtf8, $i * 2 + 1, 1));
}
}
// build low-order word and hig-order word and combine them
$combinedKey = self::buildCombinedKey($byteChars);
// build reversed hexadecimal string
$hex = str_pad(strtoupper(dechex($combinedKey & 0xFFFFFFFF)), 8, '0', \STR_PAD_LEFT);
$reversedHex = $hex[6] . $hex[7] . $hex[4] . $hex[5] . $hex[2] . $hex[3] . $hex[0] . $hex[1];
$generatedKey = mb_convert_encoding($reversedHex, 'UCS-2LE', 'UTF-8');
// Implementation Notes List:
// Word requires that the initial hash of the password with the salt not be considered in the count.
// The initial hash of salt + key is not included in the iteration count.
$algorithm = self::getAlgorithm($algorithmName);
$generatedKey = hash($algorithm, $salt . $generatedKey, true);
for ($i = 0; $i < $spinCount; $i++) {
$generatedKey = hash($algorithm, $generatedKey . pack('CCCC', $i, $i >> 8, $i >> 16, $i >> 24), true);
}
$generatedKey = base64_encode($generatedKey);
mb_internal_encoding($origEncoding);
return $generatedKey;
}
/**
* Get algorithm from self::$algorithmMapping
*
* @param string $algorithmName
* @return string
*/
private static function getAlgorithm($algorithmName)
{
$algorithm = self::$algorithmMapping[$algorithmName][1];
if ($algorithm == '') {
$algorithm = 'sha1';
}
return $algorithm;
}
/**
* Returns the algorithm ID
*
* @param string $algorithmName
* @return int
*/
public static function getAlgorithmId($algorithmName)
{
return self::$algorithmMapping[$algorithmName][0];
}
/**
* Build combined key from low-order word and high-order word
*
* @param array $byteChars byte array representation of password
* @return int
*/
private static function buildCombinedKey($byteChars)
{
$byteCharsLength = count($byteChars);
// Compute the high-order word
// Initialize from the initial code array (see above), depending on the passwords length.
$highOrderWord = self::$initialCodeArray[$byteCharsLength - 1];
// For each character in the password:
// For every bit in the character, starting with the least significant and progressing to (but excluding)
// the most significant, if the bit is set, XOR the keys high-order word with the corresponding word from
// the Encryption Matrix
for ($i = 0; $i < $byteCharsLength; $i++) {
$tmp = self::$passwordMaxLength - $byteCharsLength + $i;
$matrixRow = self::$encryptionMatrix[$tmp];
for ($intBit = 0; $intBit < 7; $intBit++) {
if (($byteChars[$i] & (0x0001 << $intBit)) != 0) {
$highOrderWord = ($highOrderWord ^ $matrixRow[$intBit]);
}
}
}
// Compute low-order word
// Initialize with 0
$lowOrderWord = 0;
// For each character in the password, going backwards
for ($i = $byteCharsLength - 1; $i >= 0; $i--) {
// low-order word = (((low-order word SHR 14) AND 0x0001) OR (low-order word SHL 1) AND 0x7FFF)) XOR character
$lowOrderWord = (((($lowOrderWord >> 14) & 0x0001) | (($lowOrderWord << 1) & 0x7FFF)) ^ $byteChars[$i]);
}
// Lastly, low-order word = (((low-order word SHR 14) AND 0x0001) OR (low-order word SHL 1) AND 0x7FFF)) XOR strPassword length XOR 0xCE4B.
$lowOrderWord = (((($lowOrderWord >> 14) & 0x0001) | (($lowOrderWord << 1) & 0x7FFF)) ^ $byteCharsLength ^ 0xCE4B);
// Combine the Low and High Order Word
return self::int32(($highOrderWord << 16) + $lowOrderWord);
}
/**
* Simulate behaviour of (signed) int32
*
* @codeCoverageIgnore
* @param int $value
* @return int
*/
private static function int32($value)
{
$value = ($value & 0xFFFFFFFF);
if ($value & 0x80000000) {
$value = -((~$value & 0xFFFFFFFF) + 1);
}
return $value;
}
}

View File

@@ -0,0 +1,232 @@
<?php
/**
* This file is part of PHPOffice Common
*
* PHPOffice Common is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/Common/contributors.
*
* @link https://github.com/PHPOffice/Common
* @copyright 2009-2016 PHPOffice Common contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\Common;
/**
* Text
*/
class Text
{
/**
* Control characters array
*
* @var string[]
*/
private static $controlCharacters = array();
/**
* Build control characters array
*/
private static function buildControlCharacters()
{
for ($i = 0; $i <= 19; ++$i) {
if ($i != 9 && $i != 10 && $i != 13) {
$find = '_x' . sprintf('%04s', strtoupper(dechex($i))) . '_';
$replace = chr($i);
self::$controlCharacters[$find] = $replace;
}
}
}
/**
* Convert from PHP control character to OpenXML escaped control character
*
* Excel 2007 team:
* ----------------
* That's correct, control characters are stored directly in the shared-strings table.
* We do encode characters that cannot be represented in XML using the following escape sequence:
* _xHHHH_ where H represents a hexadecimal character in the character's value...
* So you could end up with something like _x0008_ in a string (either in a cell value (<v>)
* element or in the shared string <t> element.
*
* @param string $value Value to escape
* @return string
*/
public static function controlCharacterPHP2OOXML($value = '')
{
if (empty(self::$controlCharacters)) {
self::buildControlCharacters();
}
return str_replace(array_values(self::$controlCharacters), array_keys(self::$controlCharacters), $value);
}
/**
* Return a number formatted for being integrated in xml files
* @param float $number
* @param integer $decimals
*/
public static function numberFormat($number, $decimals)
{
return number_format($number, $decimals, '.', '');
}
/**
* @param int $dec
* @link http://stackoverflow.com/a/7153133/2235790
* @author velcrow
*/
public static function chr($dec)
{
if ($dec<=0x7F) {
return chr($dec);
}
if ($dec<=0x7FF) {
return chr(($dec>>6)+192).chr(($dec&63)+128);
}
if ($dec<=0xFFFF) {
return chr(($dec>>12)+224).chr((($dec>>6)&63)+128).chr(($dec&63)+128);
}
if ($dec<=0x1FFFFF) {
return chr(($dec>>18)+240).chr((($dec>>12)&63)+128).chr((($dec>>6)&63)+128).chr(($dec&63)+128);
}
return '';
}
/**
* Convert from OpenXML escaped control character to PHP control character
*
* @param string $value Value to unescape
* @return string
*/
public static function controlCharacterOOXML2PHP($value = '')
{
if (empty(self::$controlCharacters)) {
self::buildControlCharacters();
}
return str_replace(array_keys(self::$controlCharacters), array_values(self::$controlCharacters), $value);
}
/**
* Check if a string contains UTF-8 data
*
* @param string $value
* @return boolean
*/
public static function isUTF8($value = '')
{
return is_string($value) && ($value === '' || preg_match('/^./su', $value) == 1);
}
/**
* Return UTF8 encoded value
*
* @param string $value
* @return string
*/
public static function toUTF8($value = '')
{
if (!is_null($value) && !self::isUTF8($value)) {
$value = utf8_encode($value);
}
return $value;
}
/**
* Returns unicode from UTF8 text
*
* The function is splitted to reduce cyclomatic complexity
*
* @param string $text UTF8 text
* @return string Unicode text
* @since 0.11.0
*/
public static function toUnicode($text)
{
return self::unicodeToEntities(self::utf8ToUnicode($text));
}
/**
* Returns unicode array from UTF8 text
*
* @param string $text UTF8 text
* @return array
* @since 0.11.0
* @link http://www.randomchaos.com/documents/?source=php_and_unicode
*/
public static function utf8ToUnicode($text)
{
$unicode = array();
$values = array();
$lookingFor = 1;
// Gets unicode for each character
for ($i = 0; $i < strlen($text); $i++) {
$thisValue = ord($text[$i]);
if ($thisValue < 128) {
$unicode[] = $thisValue;
} else {
if (count($values) == 0) {
$lookingFor = $thisValue < 224 ? 2 : 3;
}
$values[] = $thisValue;
if (count($values) == $lookingFor) {
if ($lookingFor == 3) {
$number = (($values[0] % 16) * 4096) + (($values[1] % 64) * 64) + ($values[2] % 64);
} else {
$number = (($values[0] % 32) * 64) + ($values[1] % 64);
}
$unicode[] = $number;
$values = array();
$lookingFor = 1;
}
}
}
return $unicode;
}
/**
* Returns entites from unicode array
*
* @param array $unicode
* @return string
* @since 0.11.0
* @link http://www.randomchaos.com/documents/?source=php_and_unicode
*/
private static function unicodeToEntities($unicode)
{
$entities = '';
foreach ($unicode as $value) {
if ($value != 65279) {
$entities .= $value > 127 ? '\uc0{\u' . $value . '}' : chr($value);
}
}
return $entities;
}
/**
* Return name without underscore for < 0.10.0 variable name compatibility
*
* @param string $value
* @return string
*/
public static function removeUnderscorePrefix($value)
{
if (!is_null($value)) {
if (substr($value, 0, 1) == '_') {
$value = substr($value, 1);
}
}
return $value;
}
}

View File

@@ -0,0 +1,209 @@
<?php
/**
* This file is part of PHPOffice Common
*
* PHPOffice Common is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/Common/contributors.
*
* @link https://github.com/PHPOffice/Common
* @copyright 2009-2016 PHPOffice Common contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\Common;
/**
* XML Reader wrapper
*
* @since 0.2.1
*/
class XMLReader
{
/**
* DOMDocument object
*
* @var \DOMDocument
*/
private $dom = null;
/**
* DOMXpath object
*
* @var \DOMXpath
*/
private $xpath = null;
/**
* Get DOMDocument from ZipArchive
*
* @param string $zipFile
* @param string $xmlFile
* @return \DOMDocument|false
* @throws \Exception
*/
public function getDomFromZip($zipFile, $xmlFile)
{
if (file_exists($zipFile) === false) {
throw new \Exception('Cannot find archive file.');
}
$zip = new \ZipArchive();
$zip->open($zipFile);
$content = $zip->getFromName($xmlFile);
$zip->close();
if ($content === false) {
return false;
}
return $this->getDomFromString($content);
}
/**
* Get DOMDocument from content string
*
* @param string $content
* @return \DOMDocument
*/
public function getDomFromString($content)
{
libxml_disable_entity_loader(true);
$this->dom = new \DOMDocument();
$this->dom->loadXML($content);
return $this->dom;
}
/**
* Get elements
*
* @param string $path
* @param \DOMElement $contextNode
* @return \DOMNodeList
*/
public function getElements($path, \DOMElement $contextNode = null)
{
if ($this->dom === null) {
return array();
}
if ($this->xpath === null) {
$this->xpath = new \DOMXpath($this->dom);
}
if (is_null($contextNode)) {
return $this->xpath->query($path);
}
return $this->xpath->query($path, $contextNode);
}
/**
* Registers the namespace with the DOMXPath object
*
* @param string $prefix The prefix
* @param string $namespaceURI The URI of the namespace
* @return bool true on success or false on failure
* @throws \InvalidArgumentException If called before having loaded the DOM document
*/
public function registerNamespace($prefix, $namespaceURI)
{
if ($this->dom === null) {
throw new \InvalidArgumentException('Dom needs to be loaded before registering a namespace');
}
if ($this->xpath === null) {
$this->xpath = new \DOMXpath($this->dom);
}
return $this->xpath->registerNamespace($prefix, $namespaceURI);
}
/**
* Get element
*
* @param string $path
* @param \DOMElement $contextNode
* @return \DOMElement|null
*/
public function getElement($path, \DOMElement $contextNode = null)
{
$elements = $this->getElements($path, $contextNode);
if ($elements->length > 0) {
return $elements->item(0);
}
return null;
}
/**
* Get element attribute
*
* @param string $attribute
* @param \DOMElement $contextNode
* @param string $path
* @return string|null
*/
public function getAttribute($attribute, \DOMElement $contextNode = null, $path = null)
{
$return = null;
if ($path !== null) {
$elements = $this->getElements($path, $contextNode);
if ($elements->length > 0) {
/** @var \DOMElement $node Type hint */
$node = $elements->item(0);
$return = $node->getAttribute($attribute);
}
} else {
if ($contextNode !== null) {
$return = $contextNode->getAttribute($attribute);
}
}
return ($return == '') ? null : $return;
}
/**
* Get element value
*
* @param string $path
* @param \DOMElement $contextNode
* @return string|null
*/
public function getValue($path, \DOMElement $contextNode = null)
{
$elements = $this->getElements($path, $contextNode);
if ($elements->length > 0) {
return $elements->item(0)->nodeValue;
}
return null;
}
/**
* Count elements
*
* @param string $path
* @param \DOMElement $contextNode
* @return integer
*/
public function countElements($path, \DOMElement $contextNode = null)
{
$elements = $this->getElements($path, $contextNode);
return $elements->length;
}
/**
* Element exists
*
* @param string $path
* @param \DOMElement $contextNode
* @return boolean
*/
public function elementExists($path, \DOMElement $contextNode = null)
{
return $this->getElements($path, $contextNode)->length > 0;
}
}

View File

@@ -0,0 +1,182 @@
<?php
/**
* This file is part of PHPOffice Common
*
* PHPOffice Common is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/Common/contributors.
*
* @link https://github.com/PHPOffice/Common
* @copyright 2009-2016 PHPOffice Common contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\Common;
/**
* XMLWriter
*
* @method bool endElement()
* @method mixed flush(bool $empty = null)
* @method bool openMemory()
* @method string outputMemory(bool $flush = null)
* @method bool setIndent(bool $indent)
* @method bool startDocument(string $version = 1.0, string $encoding = null, string $standalone = null)
* @method bool startElement(string $name)
* @method bool text(string $content)
* @method bool writeCData(string $content)
* @method bool writeComment(string $content)
* @method bool writeElement(string $name, string $content = null)
* @method bool writeRaw(string $content)
*/
class XMLWriter extends \XMLWriter
{
/** Temporary storage method */
const STORAGE_MEMORY = 1;
const STORAGE_DISK = 2;
/**
* Temporary filename
*
* @var string
*/
private $tempFileName = '';
/**
* Create a new \PhpOffice\PhpPowerpoint\Shared\XMLWriter instance
*
* @param int $pTemporaryStorage Temporary storage location
* @param string $pTemporaryStorageDir Temporary storage folder
*/
public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageDir = null, $compatibility = false)
{
// Open temporary storage
if ($pTemporaryStorage == self::STORAGE_MEMORY) {
$this->openMemory();
} else {
if (!is_dir($pTemporaryStorageDir)) {
$pTemporaryStorageDir = sys_get_temp_dir();
}
// Create temporary filename
$this->tempFileName = @tempnam($pTemporaryStorageDir, 'xml');
// Open storage
$this->openUri($this->tempFileName);
}
if ($compatibility) {
$this->setIndent(false);
$this->setIndentString('');
} else {
$this->setIndent(true);
$this->setIndentString(' ');
}
}
/**
* Destructor
*/
public function __destruct()
{
// Unlink temporary files
if (empty($this->tempFileName)) {
return;
}
if (PHP_OS != 'WINNT' && @unlink($this->tempFileName) === false) {
throw new \Exception('The file '.$this->tempFileName.' could not be deleted.');
}
}
/**
* Get written data
*
* @return string
*/
public function getData()
{
if ($this->tempFileName == '') {
return $this->outputMemory(true);
}
$this->flush();
return file_get_contents($this->tempFileName);
}
/**
* Write simple element and attribute(s) block
*
* There are two options:
* 1. If the `$attributes` is an array, then it's an associative array of attributes
* 2. If not, then it's a simple attribute-value pair
*
* @param string $element
* @param string|array $attributes
* @param string $value
* @return void
*/
public function writeElementBlock($element, $attributes, $value = null)
{
$this->startElement($element);
if (!is_array($attributes)) {
$attributes = array($attributes => $value);
}
foreach ($attributes as $attribute => $value) {
$this->writeAttribute($attribute, $value);
}
$this->endElement();
}
/**
* Write element if ...
*
* @param bool $condition
* @param string $element
* @param string $attribute
* @param mixed $value
* @return void
*/
public function writeElementIf($condition, $element, $attribute = null, $value = null)
{
if ($condition == true) {
if (is_null($attribute)) {
$this->writeElement($element, $value);
} else {
$this->startElement($element);
$this->writeAttribute($attribute, $value);
$this->endElement();
}
}
}
/**
* Write attribute if ...
*
* @param bool $condition
* @param string $attribute
* @param mixed $value
* @return void
*/
public function writeAttributeIf($condition, $attribute, $value)
{
if ($condition == true) {
$this->writeAttribute($attribute, $value);
}
}
/**
* @param string $name
* @param mixed $value
* @return bool
*/
public function writeAttribute($name, $value)
{
if (is_float($value)) {
$value = json_encode($value);
}
return parent::writeAttribute($name, $value);
}
}

View File

@@ -0,0 +1,61 @@
<?php
namespace Common\Tests\Adapter\Zip;
use PhpOffice\Common\Tests\TestHelperZip;
abstract class AbstractZipAdapterTest extends \PHPUnit\Framework\TestCase
{
protected $zipTest;
/**
* Returns a new instance of the adapter to test
* @return \PhpOffice\Common\Adapter\Zip\ZipInterface
*/
abstract protected function createAdapter();
public function setUp()
{
parent::setUp();
$pathResources = PHPOFFICE_COMMON_TESTS_BASE_DIR.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'files'.DIRECTORY_SEPARATOR;
$this->zipTest = tempnam(sys_get_temp_dir(), 'PhpOfficeCommon');
copy($pathResources.'Sample_01_Simple.pptx', $this->zipTest);
}
public function tearDown()
{
parent::tearDown();
if (is_file($this->zipTest)) {
unlink($this->zipTest);
}
}
public function testOpen()
{
$adapter = $this->createAdapter();
$this->assertSame($adapter, $adapter->open($this->zipTest));
}
public function testClose()
{
$adapter = $this->createAdapter();
$adapter->open($this->zipTest);
$this->assertSame($adapter, $adapter->close());
}
public function testAddFromString()
{
$expectedPath = 'file.test';
$expectedContent = 'Content';
$adapter = $this->createAdapter();
$adapter->open($this->zipTest);
$this->assertSame($adapter, $adapter->addFromString($expectedPath, $expectedContent));
$adapter->close();
$this->assertTrue(TestHelperZip::assertFileExists($this->zipTest, $expectedPath));
$this->assertTrue(TestHelperZip::assertFileContent($this->zipTest, $expectedPath, $expectedContent));
}
}

View File

@@ -0,0 +1,14 @@
<?php
namespace Common\Tests\Adapter\Zip;
use PhpOffice\Common\Adapter\Zip\PclZipAdapter;
use PhpOffice\Common\Tests\TestHelperZip;
class PclZipAdapterTest extends AbstractZipAdapterTest
{
protected function createAdapter()
{
return new PclZipAdapter();
}
}

View File

@@ -0,0 +1,14 @@
<?php
namespace Common\Tests\Adapter\Zip;
use PhpOffice\Common\Adapter\Zip\ZipArchiveAdapter;
use PhpOffice\Common\Tests\TestHelperZip;
class ZipArchiveAdapterTest extends AbstractZipAdapterTest
{
protected function createAdapter()
{
return new ZipArchiveAdapter();
}
}

View File

@@ -0,0 +1,53 @@
<?php
/**
* This file is part of PHPOffice Common
*
* PHPOffice Common is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/Common/contributors.
*
* @link https://github.com/PHPOffice/Common
* @copyright 2009-2016 PHPOffice Common contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\Common\Tests;
use PhpOffice\Common\Autoloader;
/**
* Test class for Autoloader
*/
class AutoloaderTest extends \PHPUnit\Framework\TestCase
{
/**
* Register
*/
public function testRegister()
{
Autoloader::register();
$this->assertContains(
array('PhpOffice\\Common\\Autoloader', 'autoload'),
spl_autoload_functions()
);
}
/**
* Autoload
*/
public function testAutoload()
{
$declared = get_declared_classes();
$declaredCount = count($declared);
Autoloader::autoload('Foo');
$this->assertEquals(
$declaredCount,
count(get_declared_classes()),
'PhpOffice\\Common\\Autoloader::autoload() is trying to load ' .
'classes outside of the PhpOffice\\Common namespace'
);
}
}

View File

@@ -0,0 +1,125 @@
<?php
/**
* This file is part of PHPOffice Common
*
* PHPOffice Common is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/Common/contributors.
*
* @link https://github.com/PHPOffice/Common
* @copyright 2009-2016 PHPOffice Common contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\Common\Tests;
use PhpOffice\Common\Drawing;
/**
* Test class for IOFactory
*
* @coversDefaultClass PhpOffice\Common\IOFactory
*/
class DrawingTest extends \PHPUnit\Framework\TestCase
{
/**
*/
public function testDegreesAngle()
{
$value = rand(1, 100);
$this->assertEquals(0, Drawing::degreesToAngle());
$this->assertEquals((int) round($value * 60000), Drawing::degreesToAngle($value));
$this->assertEquals(0, Drawing::angleToDegrees());
$this->assertEquals(round($value / 60000), Drawing::angleToDegrees($value));
}
/**
*/
public function testPixelsCentimeters()
{
$value = rand(1, 100);
$this->assertEquals(0, Drawing::pixelsToCentimeters());
$this->assertEquals($value / Drawing::DPI_96 * 2.54, Drawing::pixelsToCentimeters($value));
$this->assertEquals(0, Drawing::centimetersToPixels());
$this->assertEquals($value / 2.54 * Drawing::DPI_96, Drawing::centimetersToPixels($value));
}
/**
*/
public function testPixelsEMU()
{
$value = rand(1, 100);
$this->assertEquals(0, Drawing::pixelsToEmu());
$this->assertEquals(round($value*9525), Drawing::pixelsToEmu($value));
$this->assertEquals(0, Drawing::emuToPixels());
$this->assertEquals(round($value/9525), Drawing::emuToPixels($value));
}
/**
*/
public function testPixelsPoints()
{
$value = rand(1, 100);
$this->assertEquals(0, Drawing::pixelsToPoints());
$this->assertEquals($value*0.67777777, Drawing::pixelsToPoints($value));
$this->assertEquals(0, Drawing::pointsToPixels());
$this->assertEquals($value* 1.333333333, Drawing::pointsToPixels($value));
}
/**
*/
public function testPointsCentimeters()
{
$value = rand(1, 100);
$this->assertEquals(0, Drawing::pointsToCentimeters());
$this->assertEquals($value * 1.333333333 / Drawing::DPI_96 * 2.54, Drawing::pointsToCentimeters($value));
}
/**
*/
public function testTwips()
{
$value = rand(1, 100);
// Centimeters
$this->assertEquals(0, Drawing::centimetersToTwips());
$this->assertEquals($value * 566.928, Drawing::centimetersToTwips($value));
$this->assertEquals(0, Drawing::twipsToCentimeters());
$this->assertEquals($value / 566.928, Drawing::twipsToCentimeters($value));
// Inches
$this->assertEquals(0, Drawing::inchesToTwips());
$this->assertEquals($value * 1440, Drawing::inchesToTwips($value));
$this->assertEquals(0, Drawing::twipsToInches());
$this->assertEquals($value / 1440, Drawing::twipsToInches($value));
// Pixels
$this->assertEquals(0, Drawing::twipsToPixels());
$this->assertEquals(round($value / 15.873984), Drawing::twipsToPixels($value));
}
public function testHTML()
{
$this->assertFalse(Drawing::htmlToRGB('0'));
$this->assertFalse(Drawing::htmlToRGB('00'));
$this->assertFalse(Drawing::htmlToRGB('0000'));
$this->assertFalse(Drawing::htmlToRGB('00000'));
$this->assertInternalType('array', Drawing::htmlToRGB('ABCDEF'));
$this->assertCount(3, Drawing::htmlToRGB('ABCDEF'));
$this->assertEquals(array(0xAB, 0xCD, 0xEF), Drawing::htmlToRGB('ABCDEF'));
$this->assertEquals(array(0xAB, 0xCD, 0xEF), Drawing::htmlToRGB('#ABCDEF'));
$this->assertEquals(array(0xAA, 0xBB, 0xCC), Drawing::htmlToRGB('ABC'));
$this->assertEquals(array(0xAA, 0xBB, 0xCC), Drawing::htmlToRGB('#ABC'));
}
}

View File

@@ -0,0 +1,62 @@
<?php
/**
* This file is part of PHPOffice Common
*
* PHPOffice Common is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/Common/contributors.
*
* @link https://github.com/PHPOffice/Common
* @copyright 2009-2016 PHPOffice Common contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\Common\Tests;
use PhpOffice\Common\File;
/**
* Test class for File
*
* @coversDefaultClass PhpOffice\Common\File
*/
class FileTest extends \PHPUnit\Framework\TestCase
{
/**
*/
public function testFileExists()
{
$pathResources = PHPOFFICE_COMMON_TESTS_BASE_DIR.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR;
$this->assertTrue(File::fileExists($pathResources.'images'.DIRECTORY_SEPARATOR.'PHPPowerPointLogo.png'));
$this->assertFalse(File::fileExists($pathResources.'images'.DIRECTORY_SEPARATOR.'PHPPowerPointLogo_404.png'));
$this->assertTrue(File::fileExists('zip://'.$pathResources.'files'.DIRECTORY_SEPARATOR.'Sample_01_Simple.pptx#[Content_Types].xml'));
$this->assertFalse(File::fileExists('zip://'.$pathResources.'files'.DIRECTORY_SEPARATOR.'Sample_01_Simple.pptx#404.xml'));
$this->assertFalse(File::fileExists('zip://'.$pathResources.'files'.DIRECTORY_SEPARATOR.'404.pptx#404.xml'));
}
/**
*/
public function testGetFileContents()
{
$pathResources = PHPOFFICE_COMMON_TESTS_BASE_DIR.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR;
$this->assertInternalType('string', File::fileGetContents($pathResources.'images'.DIRECTORY_SEPARATOR.'PHPPowerPointLogo.png'));
$this->assertFalse(File::fileGetContents($pathResources.'images'.DIRECTORY_SEPARATOR.'PHPPowerPointLogo_404.png'));
$this->assertInternalType('string', File::fileGetContents('zip://'.$pathResources.'files'.DIRECTORY_SEPARATOR.'Sample_01_Simple.pptx#[Content_Types].xml'));
$this->assertFalse(File::fileGetContents('zip://'.$pathResources.'files'.DIRECTORY_SEPARATOR.'Sample_01_Simple.pptx#404.xml'));
$this->assertFalse(File::fileGetContents('zip://'.$pathResources.'files'.DIRECTORY_SEPARATOR.'404.pptx#404.xml'));
}
/**
*/
public function testRealPath()
{
$pathFiles = PHPOFFICE_COMMON_TESTS_BASE_DIR.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'files'.DIRECTORY_SEPARATOR;
$this->assertEquals($pathFiles.'Sample_01_Simple.pptx', File::realpath($pathFiles.'Sample_01_Simple.pptx'));
$this->assertEquals('zip://'.$pathFiles.'Sample_01_Simple.pptx#[Content_Types].xml', File::realpath('zip://'.$pathFiles.'Sample_01_Simple.pptx#[Content_Types].xml'));
$this->assertEquals('zip://'.$pathFiles.'Sample_01_Simple.pptx#/[Content_Types].xml', File::realpath('zip://'.$pathFiles.'Sample_01_Simple.pptx#/rels/../[Content_Types].xml'));
}
}

View File

@@ -0,0 +1,44 @@
<?php
/**
* This file is part of PHPOffice Common
*
* PHPOffice Common is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/Common/contributors.
*
* @link https://github.com/PHPOffice/Common
* @copyright 2009-2016 PHPOffice Common contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\Common\Tests;
use PhpOffice\Common\Font;
/**
* Test class for Font
*
* @coversDefaultClass PhpOffice\Common\Font
*/
class FontTest extends \PHPUnit\Framework\TestCase
{
/**
*/
public function testMath()
{
$value = rand(1, 100);
$this->assertEquals(16, Font::fontSizeToPixels());
$this->assertEquals((16 / 12) * $value, Font::fontSizeToPixels($value));
$this->assertEquals(96, Font::inchSizeToPixels());
$this->assertEquals(96 * $value, Font::inchSizeToPixels($value));
$this->assertEquals(37.795275591, Font::centimeterSizeToPixels());
$this->assertEquals(37.795275591 * $value, Font::centimeterSizeToPixels($value));
$this->assertEquals($value / 2.54 * 1440, Font::centimeterSizeToTwips($value));
$this->assertEquals($value * 1440, Font::inchSizeToTwips($value));
$this->assertEquals($value / 96 * 1440, Font::pixelSizeToTwips($value));
$this->assertEquals($value / 72 * 1440, Font::pointSizeToTwips($value));
}
}

View File

@@ -0,0 +1,89 @@
<?php
/**
* This file is part of PHPOffice Common
*
* PHPOffice Common is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/Common/contributors.
*
* @link https://github.com/PHPOffice/Common
* @copyright 2009-2016 PHPOffice Common contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\Common\Tests\Microsoft;
use PhpOffice\Common\Microsoft\PasswordEncoder;
/**
* Test class for PhpOffice\Common\PasswordEncoder
* @coversDefaultClass \PhpOffice\Common\PasswordEncoder
*/
class PasswordEncoderTest extends \PHPUnit\Framework\TestCase
{
/**
* Test that a password can be hashed without specifying any additional parameters
*/
public function testEncodePassword()
{
//given
$password = 'test';
//when
$hashPassword = PasswordEncoder::hashPassword($password);
//then
$this->assertEquals('M795/MAlmGU8RIsY9Q9uDLHC7bk=', $hashPassword);
}
/**
* Test that a password can be hashed with a custom salt
*/
public function testEncodePasswordWithSalt()
{
//given
$password = 'test';
$salt = base64_decode('uq81pJRRGFIY5U+E9gt8tA==');
//when
$hashPassword = PasswordEncoder::hashPassword($password, PasswordEncoder::ALGORITHM_SHA_1, $salt);
//then
$this->assertEquals('QiDOcpia1YzSVJPiKPwWebl9p/0=', $hashPassword);
}
/**
* Test that the encoder falls back on SHA-1 if a non supported algorithm is given
*/
public function testDefaultsToSha1IfUnsupportedAlgorithm()
{
//given
$password = 'test';
$salt = base64_decode('uq81pJRRGFIY5U+E9gt8tA==');
//when
$hashPassword = PasswordEncoder::hashPassword($password, PasswordEncoder::ALGORITHM_MAC, $salt);
//then
$this->assertEquals('QiDOcpia1YzSVJPiKPwWebl9p/0=', $hashPassword);
}
/**
* Test that the encoder falls back on SHA-1 if a non supported algorithm is given
*/
public function testEncodePasswordWithNullAsciiCodeInPassword()
{
//given
$password = 'test' . chr(0);
$salt = base64_decode('uq81pJRRGFIY5U+E9gt8tA==');
//when
$hashPassword = PasswordEncoder::hashPassword($password, PasswordEncoder::ALGORITHM_MAC, $salt, 1);
//then
$this->assertEquals('rDV9sgdDsztoCQlvRCb1lF2wxNg=', $hashPassword);
}
}

View File

@@ -0,0 +1,89 @@
<?php
/**
* This file is part of PHPOffice Common
*
* PHPOffice Common is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/Common/contributors.
*
* @link https://github.com/PHPOffice/Common
* @copyright 2009-2016 PHPOffice Common contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\Common\Tests;
use PhpOffice\Common\Text;
/**
* Test class for Text
*
* @coversDefaultClass PhpOffice\Common\Text
*/
class TextTest extends \PHPUnit\Framework\TestCase
{
/**
*/
public function testControlCharacters()
{
$this->assertEquals('', Text::controlCharacterPHP2OOXML());
$this->assertEquals('aeiou', Text::controlCharacterPHP2OOXML('aeiou'));
$this->assertEquals('àéîöù', Text::controlCharacterPHP2OOXML('àéîöù'));
$value = rand(0, 8);
$this->assertEquals('_x'.sprintf('%04s', strtoupper(dechex($value))).'_', Text::controlCharacterPHP2OOXML(chr($value)));
$this->assertEquals('', Text::controlCharacterOOXML2PHP(''));
$this->assertEquals(chr(0x08), Text::controlCharacterOOXML2PHP('_x0008_'));
}
public function testNumberFormat()
{
$this->assertEquals('2.1', Text::numberFormat('2.06', 1));
$this->assertEquals('2.1', Text::numberFormat('2.12', 1));
$this->assertEquals('1234.0', Text::numberFormat(1234, 1));
}
public function testChr()
{
$this->assertEquals('A', Text::chr(65));
$this->assertEquals('A', Text::chr(0x41));
$this->assertEquals('é', Text::chr(233));
$this->assertEquals('é', Text::chr(0xE9));
$this->assertEquals('⼳', Text::chr(12083));
$this->assertEquals('⼳', Text::chr(0x2F33));
$this->assertEquals('🌃', Text::chr(127747));
$this->assertEquals('🌃', Text::chr(0x1F303));
$this->assertEquals('', Text::chr(2097152));
}
/**
* Is UTF8
*/
public function testIsUTF8()
{
$this->assertTrue(Text::isUTF8(''));
$this->assertTrue(Text::isUTF8('éééé'));
$this->assertFalse(Text::isUTF8(utf8_decode('éééé')));
}
/**
* Test unicode conversion
*/
public function testToUnicode()
{
$this->assertEquals('a', Text::toUnicode('a'));
$this->assertEquals('\uc0{\u8364}', Text::toUnicode('€'));
$this->assertEquals('\uc0{\u233}', Text::toUnicode('é'));
}
/**
* Test remove underscore prefix
*/
public function testRemoveUnderscorePrefix()
{
$this->assertEquals('item', Text::removeUnderscorePrefix('_item'));
}
}

View File

@@ -0,0 +1,135 @@
<?php
/**
* This file is part of PHPOffice Common
*
* PHPOffice Common is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/Common/contributors.
*
* @link https://github.com/PHPOffice/Common
* @copyright 2009-2017 PHPOffice Common contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\Common\Tests;
use PhpOffice\Common\XMLReader;
/**
* Test class for XMLReader
*
* @coversDefaultClass PhpOffice\Common\XMLReader
*/
class XMLReaderTest extends \PHPUnit\Framework\TestCase
{
/**
* Test reading XML from string
*/
public function testDomFromString()
{
$reader = new XMLReader();
$reader->getDomFromString('<element attr="test"><child attr="subtest">AAA</child></element>');
$this->assertTrue($reader->elementExists('/element/child'));
$this->assertEquals('AAA', $reader->getElement('/element/child')->textContent);
$this->assertEquals('AAA', $reader->getValue('/element/child'));
$this->assertEquals('test', $reader->getAttribute('attr', $reader->getElement('/element')));
$this->assertEquals('subtest', $reader->getAttribute('attr', $reader->getElement('/element'), 'child'));
}
/**
* Test reading XML from zip
*/
public function testDomFromZip()
{
$pathResources = PHPOFFICE_COMMON_TESTS_BASE_DIR.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'files'.DIRECTORY_SEPARATOR;
$reader = new XMLReader();
$reader->getDomFromZip($pathResources. 'reader.zip', 'test.xml');
$this->assertTrue($reader->elementExists('/element/child'));
$this->assertFalse($reader->getDomFromZip($pathResources. 'reader.zip', 'non_existing_xml_file.xml'));
}
/**
* Test that read from non existing archive throws exception
*
* @expectedException Exception
*/
public function testThrowsExceptionOnNonExistingArchive()
{
$pathResources = PHPOFFICE_COMMON_TESTS_BASE_DIR.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'files'.DIRECTORY_SEPARATOR;
$reader = new XMLReader();
$reader->getDomFromZip($pathResources. 'readers.zip', 'test.xml');
}
/**
* Test elements count
*/
public function testCountElements()
{
$reader = new XMLReader();
$reader->getDomFromString('<element attr="test"><child>AAA</child><child>BBB</child></element>');
$this->assertEquals(2, $reader->countElements('/element/child'));
}
/**
* Test read non existing elements
*/
public function testReturnNullOnNonExistingNode()
{
$reader = new XMLReader();
$this->assertEmpty($reader->getElements('/element/children'));
$reader->getDomFromString('<element><child>AAA</child></element>');
$this->assertNull($reader->getElement('/element/children'));
$this->assertNull($reader->getValue('/element/children'));
}
/**
* Test that xpath fails if custom namespace is not registered
*/
public function testShouldThrowExceptionIfNamespaceIsNotKnown()
{
try {
$reader = new XMLReader();
$reader->getDomFromString('<element><test:child xmlns:test="http://phpword.com/my/custom/namespace">AAA</test:child></element>');
$this->assertTrue($reader->elementExists('/element/test:child'));
$this->assertEquals('AAA', $reader->getElement('/element/test:child')->textContent);
$this->fail();
} catch (\Exception $e) {
$this->assertTrue(true);
}
}
/**
* Test reading XML with manually registered namespace
*/
public function testShouldParseXmlWithCustomNamespace()
{
$reader = new XMLReader();
$reader->getDomFromString('<element><test:child xmlns:test="http://phpword.com/my/custom/namespace">AAA</test:child></element>');
$reader->registerNamespace('test', 'http://phpword.com/my/custom/namespace');
$this->assertTrue($reader->elementExists('/element/test:child'));
$this->assertEquals('AAA', $reader->getElement('/element/test:child')->textContent);
}
/**
* Test that xpath fails if custom namespace is not registered
*
* @expectedException InvalidArgumentException
*/
public function testShouldThowExceptionIfTryingToRegisterNamespaceBeforeReadingDoc()
{
$reader = new XMLReader();
$reader->registerNamespace('test', 'http://phpword.com/my/custom/namespace');
}
}

View File

@@ -0,0 +1,71 @@
<?php
/**
* This file is part of PHPOffice Common
*
* PHPOffice Common is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/Common/contributors.
*
* @link https://github.com/PHPOffice/Common
* @copyright 2009-2016 PHPOffice Common contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\Common\Tests;
use PhpOffice\Common\XMLWriter;
/**
* Test class for XMLWriter
*
* @coversDefaultClass PhpOffice\Common\XMLWriter
*/
class XMLWriterTest extends \PHPUnit\Framework\TestCase
{
/**
*/
public function testConstruct()
{
// Memory
$object = new XMLWriter();
$object->startElement('element');
$object->text('AAA');
$object->endElement();
$this->assertEquals('<element>AAA</element>'.chr(10), $object->getData());
// Disk
$object = new XMLWriter(XMLWriter::STORAGE_DISK);
$object->startElement('element');
$object->text('BBB');
$object->endElement();
$this->assertEquals('<element>BBB</element>'.chr(10), $object->getData());
}
public function testWriteAttribute()
{
$xmlWriter = new XMLWriter();
$xmlWriter->startElement('element');
$xmlWriter->writeAttribute('name', 'value');
$xmlWriter->endElement();
$this->assertSame('<element name="value"/>' . chr(10), $xmlWriter->getData());
}
public function testWriteAttributeShouldWriteFloatValueLocaleIndependent()
{
$value = 1.2;
$xmlWriter = new XMLWriter();
$xmlWriter->startElement('element');
$xmlWriter->writeAttribute('name', $value);
$xmlWriter->endElement();
setlocale(LC_NUMERIC, 'de_DE.UTF-8', 'de');
$this->assertSame('1,2', (string)$value);
$this->assertSame('<element name="1.2"/>' . chr(10), $xmlWriter->getData());
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace PhpOffice\Common\Tests;
class TestHelperZip
{
public static function assertFileExists($fileZip, $path)
{
$oZip = new \ZipArchive;
if ($oZip->open($fileZip) !== true) {
return false;
}
if ($oZip->statName($path) === false) {
return false;
}
return true;
}
public static function assertFileContent($fileZip, $path, $content)
{
$oZip = new \ZipArchive;
if ($oZip->open($fileZip) !== true) {
return false;
}
$zipFileContent = $oZip->getFromName($path);
if ($zipFileContent === false) {
return false;
}
if ($zipFileContent != $content) {
return false;
}
return true;
}
}

View File

@@ -0,0 +1,175 @@
<?php
/**
* This file is part of PHPPowerPoint - A pure PHP library for reading and writing
* word processing documents.
*
* PHPPowerPoint is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPPowerPoint/contributors.
*
* @link https://github.com/PHPOffice/PHPPowerPoint
* @copyright 2010-2016 PHPPowerPoint contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpPowerpoint\Tests;
/**
* DOM wrapper class
*/
class XmlDocument
{
/**
* Path
*
* @var string $path
*/
private $path;
/**
* DOMDocument object
*
* @var \DOMDocument
*/
private $dom;
/**
* DOMXpath object
*
* @var \DOMXpath
*/
private $xpath;
/**
* File name
*
* @var string
*/
private $file;
/**
* Create new instance
*
* @param string $path
*/
public function __construct($path)
{
$this->path = realpath($path);
}
/**
* Get DOM from file
*
* @param string $file
* @return \DOMDocument
*/
public function getFileDom($file = 'word/document.xml')
{
if (null !== $this->dom && $file === $this->file) {
return $this->dom;
}
$this->xpath = null;
$this->file = $file;
$file = $this->path . '/' . $file;
$this->dom = new \DOMDocument();
$this->dom->load($file);
return $this->dom;
}
/**
* Get node list
*
* @param string $path
* @param string $file
* @return \DOMNodeList
*/
public function getNodeList($path, $file = 'word/document.xml')
{
if ($this->dom === null || $file !== $this->file) {
$this->getFileDom($file);
}
if (null === $this->xpath) {
$this->xpath = new \DOMXpath($this->dom);
}
return $this->xpath->query($path);
}
/**
* Get element
*
* @param string $path
* @param string $file
* @return \DOMElement
*/
public function getElement($path, $file = 'word/document.xml')
{
$elements = $this->getNodeList($path, $file);
return $elements->item(0);
}
/**
* Get file name
*
* @return string
*/
public function getFile()
{
return $this->file;
}
/**
* Get path
*
* @return string
*/
public function getPath()
{
return $this->path;
}
/**
* Get element attribute
*
* @param string $path
* @param string $attribute
* @param string $file
* @return string
*/
public function getElementAttribute($path, $attribute, $file = 'word/document.xml')
{
return $this->getElement($path, $file)->getAttribute($attribute);
}
/**
* Get element attribute
*
* @param string $path
* @param string $attribute
* @param string $file
* @return string
*/
public function attributeElementExists($path, $attribute, $file = 'word/document.xml')
{
return $this->getElement($path, $file)->hasAttribute($attribute);
}
/**
* Check if element exists
*
* @param string $path
* @param string $file
* @return string
*/
public function elementExists($path, $file = 'word/document.xml')
{
$nodeList = $this->getNodeList($path, $file);
return !($nodeList->length == 0);
}
}

View File

@@ -0,0 +1,52 @@
<?php
/**
* This file is part of PHPOffice Common
*
* PHPOffice Common is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/Common/contributors.
*
* @copyright 2010-2016 PHPOffice Common contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
* @link https://github.com/PHPOffice/Common
*/
date_default_timezone_set('UTC');
// defining base dir for tests
if (!defined('PHPOFFICE_COMMON_TESTS_BASE_DIR')) {
define('PHPOFFICE_COMMON_TESTS_BASE_DIR', realpath(__DIR__));
}
$vendor = realpath(__DIR__ . '/../vendor');
if (file_exists($vendor . "/autoload.php")) {
require $vendor . "/autoload.php";
} else {
$vendor = realpath(__DIR__ . '/../../../');
if (file_exists($vendor . "/autoload.php")) {
require $vendor . "/autoload.php";
} else {
throw new Exception("Unable to load dependencies");
}
}
spl_autoload_register(function ($class) {
$class = ltrim($class, '\\');
$prefix = 'PhpOffice\\Common\\Tests';
if (strpos($class, $prefix) === 0) {
$class = str_replace('\\', DIRECTORY_SEPARATOR, $class);
$class = join(DIRECTORY_SEPARATOR, array('Common', 'Tests', '_includes')) .
substr($class, strlen($prefix));
$file = __DIR__ . DIRECTORY_SEPARATOR . $class . '.php';
if (file_exists($file)) {
require_once $file;
}
}
});
require_once __DIR__ . "/../src/Common/Autoloader.php";
\PhpOffice\Common\Autoloader::register();

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB