├── VERSION
├── tests
├── resources
│ ├── files
│ │ ├── reader.zip
│ │ └── Sample_01_Simple.pptx
│ └── images
│ │ └── PHPPowerPointLogo.png
├── Common
│ └── Tests
│ │ ├── Adapter
│ │ └── Zip
│ │ │ ├── PclZipAdapterTest.php
│ │ │ ├── ZipArchiveAdapterTest.php
│ │ │ └── AbstractZipAdapter.php
│ │ ├── _includes
│ │ ├── TestHelperZip.php
│ │ └── XmlDocument.php
│ │ ├── AutoloaderTest.php
│ │ ├── FontTest.php
│ │ ├── Microsoft
│ │ └── PasswordEncoderTest.php
│ │ ├── TextTest.php
│ │ ├── FileTest.php
│ │ ├── DrawingTest.php
│ │ ├── XMLReaderTest.php
│ │ └── XMLWriterTest.php
└── bootstrap.php
├── .gitignore
├── .github
├── dependabot.yml
└── workflows
│ └── php.yml
├── phpstan.neon.dist
├── LICENSE
├── phpunit.xml.dist
├── composer.json
├── src
└── Common
│ ├── Adapter
│ └── Zip
│ │ ├── ZipInterface.php
│ │ ├── ZipArchiveAdapter.php
│ │ └── PclZipAdapter.php
│ ├── Autoloader.php
│ ├── Font.php
│ ├── File.php
│ ├── XMLWriter.php
│ ├── XMLReader.php
│ ├── Text.php
│ ├── Drawing.php
│ └── Microsoft
│ ├── PasswordEncoder.php
│ └── OLERead.php
├── .php-cs-fixer.dist.php
├── phpmd.xml.dist
├── README.md
├── COPYING.LESSER
└── COPYING
/VERSION:
--------------------------------------------------------------------------------
1 | 1.0.5
--------------------------------------------------------------------------------
/tests/resources/files/reader.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PHPOffice/Common/HEAD/tests/resources/files/reader.zip
--------------------------------------------------------------------------------
/tests/resources/files/Sample_01_Simple.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PHPOffice/Common/HEAD/tests/resources/files/Sample_01_Simple.pptx
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## PHPCSFixer
2 | /.php-cs-fixer.cache
3 | ## PHPUnit
4 | /.phpunit.result.cache
5 | ## Dependencies
6 | /composer.lock
7 | /vendor/
--------------------------------------------------------------------------------
/tests/resources/images/PHPPowerPointLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PHPOffice/Common/HEAD/tests/resources/images/PHPPowerPointLogo.png
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: composer
4 | directory: "/"
5 | schedule:
6 | interval: monthly
7 | time: "11:00"
8 | open-pull-requests-limit: 10
9 | assignees:
10 | - Progi1984
11 |
--------------------------------------------------------------------------------
/phpstan.neon.dist:
--------------------------------------------------------------------------------
1 | parameters:
2 | level: 6
3 | bootstrapFiles:
4 | - tests/bootstrap.php
5 | paths:
6 | - src
7 | - tests
8 | reportUnmatchedIgnoredErrors: false
9 | ignoreErrors:
10 | # # PHP 8.0 & Attribute
11 | - '#^Attribute class PHPUnit\\Framework\\Attributes\\DataProvider does not exist\.#'
12 |
13 | ## Remove after remove ArrayObject
14 | treatPhpDocTypesAsCertain: false
15 |
--------------------------------------------------------------------------------
/tests/Common/Tests/Adapter/Zip/PclZipAdapterTest.php:
--------------------------------------------------------------------------------
1 | .
16 |
--------------------------------------------------------------------------------
/phpunit.xml.dist:
--------------------------------------------------------------------------------
1 |
11 |
12 |
13 | ./src
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | ./tests/Common
23 |
24 |
25 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "phpoffice/common",
3 | "description": "PHPOffice Common",
4 | "keywords": ["PHP","Office","Common","component"],
5 | "homepage": "http://phpoffice.github.io",
6 | "type": "library",
7 | "license": "LGPL-3.0-only",
8 | "authors": [
9 | {
10 | "name": "Mark Baker"
11 | },
12 | {
13 | "name": "Franck Lefevre",
14 | "homepage": "http://rootslabs.net"
15 | }
16 | ],
17 | "require": {
18 | "php": ">=7.1",
19 | "pclzip/pclzip": "^2.8"
20 | },
21 | "require-dev": {
22 | "phpunit/phpunit": ">=7",
23 | "phpmd/phpmd": "2.*",
24 | "phpstan/phpstan": "^0.12.88 || ^1.0.0"
25 | },
26 | "autoload": {
27 | "psr-4": {
28 | "PhpOffice\\Common\\": "src/Common/"
29 | }
30 | },
31 | "autoload-dev": {
32 | "psr-4": {
33 | "PhpOffice\\Common\\Tests\\": "tests/Common/Tests"
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Common/Adapter/Zip/ZipInterface.php:
--------------------------------------------------------------------------------
1 | open($fileZip) !== true) {
11 | return false;
12 | }
13 | if ($oZip->statName($path) === false) {
14 | return false;
15 | }
16 |
17 | return true;
18 | }
19 |
20 | public static function assertFileContent(string $fileZip, string $path, string $content): bool
21 | {
22 | $oZip = new \ZipArchive();
23 | if ($oZip->open($fileZip) !== true) {
24 | return false;
25 | }
26 | $zipFileContent = $oZip->getFromName($path);
27 | if ($zipFileContent === false) {
28 | return false;
29 | }
30 | if ($zipFileContent != $content) {
31 | return false;
32 | }
33 |
34 | return true;
35 | }
36 |
37 | public static function assertFileIsCompressed(string $fileZip, string $path): bool
38 | {
39 | $oZip = new \ZipArchive();
40 | $oZip->open($fileZip);
41 | $stat = $oZip->statName($path);
42 |
43 | // size: uncompressed
44 | // comp_size: compressed
45 |
46 | return $stat['size'] > $stat['comp_size'];
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/.php-cs-fixer.dist.php:
--------------------------------------------------------------------------------
1 | setUsingCache(true)
7 | ->setRiskyAllowed(true)
8 | ->setRules([
9 | '@Symfony' => true,
10 | 'array_indentation' => true,
11 | 'cast_spaces' => [
12 | 'space' => 'single',
13 | ],
14 | 'combine_consecutive_issets' => true,
15 | 'concat_space' => [
16 | 'spacing' => 'one',
17 | ],
18 | 'error_suppression' => [
19 | 'mute_deprecation_error' => false,
20 | 'noise_remaining_usages' => false,
21 | 'noise_remaining_usages_exclude' => [],
22 | ],
23 | 'function_to_constant' => false,
24 | 'method_chaining_indentation' => true,
25 | 'no_alias_functions' => false,
26 | 'no_superfluous_phpdoc_tags' => false,
27 | 'non_printable_character' => [
28 | 'use_escape_sequences_in_strings' => true,
29 | ],
30 | 'phpdoc_align' => [
31 | 'align' => 'left',
32 | ],
33 | 'phpdoc_summary' => false,
34 | 'protected_to_private' => false,
35 | 'self_accessor' => false,
36 | 'yoda_style' => false,
37 | 'single_line_throw' => false,
38 | 'no_alias_language_construct_call' => false,
39 | ])
40 | ->getFinder()
41 | ->in(__DIR__)
42 | ->exclude('vendor');
43 |
44 | return $config;
--------------------------------------------------------------------------------
/phpmd.xml.dist:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/src/Common/Adapter/Zip/ZipArchiveAdapter.php:
--------------------------------------------------------------------------------
1 | filename = $filename;
20 | $this->oZipArchive = new \ZipArchive();
21 |
22 | if ($this->oZipArchive->open($this->filename, \ZipArchive::OVERWRITE) === true) {
23 | return $this;
24 | }
25 | if ($this->oZipArchive->open($this->filename, \ZipArchive::CREATE) === true) {
26 | return $this;
27 | }
28 | throw new \Exception("Could not open $this->filename for writing.");
29 | }
30 |
31 | public function close()
32 | {
33 | if ($this->oZipArchive->close() === false) {
34 | throw new \Exception("Could not close zip file $this->filename.");
35 | }
36 |
37 | return $this;
38 | }
39 |
40 | public function addFromString(string $localname, string $contents, bool $withCompression = true)
41 | {
42 | if ($this->oZipArchive->addFromString($localname, $contents) === false) {
43 | throw new \Exception('Error zipping files : ' . $localname);
44 | }
45 | if (!$withCompression) {
46 | $this->oZipArchive->setCompressionName($localname, \ZipArchive::CM_STORE);
47 | }
48 |
49 | return $this;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/Common/Adapter/Zip/PclZipAdapter.php:
--------------------------------------------------------------------------------
1 | oPclZip = new \PclZip($filename);
20 | $this->tmpDir = sys_get_temp_dir();
21 |
22 | return $this;
23 | }
24 |
25 | public function close()
26 | {
27 | return $this;
28 | }
29 |
30 | public function addFromString(string $localname, string $contents, bool $withCompression = true)
31 | {
32 | $pathData = pathinfo($localname);
33 |
34 | $hFile = fopen($this->tmpDir . '/' . $pathData['basename'], 'wb');
35 | fwrite($hFile, $contents);
36 | fclose($hFile);
37 |
38 | $params = [
39 | $this->tmpDir . '/' . $pathData['basename'],
40 | PCLZIP_OPT_REMOVE_PATH,
41 | $this->tmpDir,
42 | PCLZIP_OPT_ADD_PATH,
43 | $pathData['dirname'],
44 | ];
45 | if (!$withCompression) {
46 | $params[] = PCLZIP_OPT_NO_COMPRESSION;
47 | }
48 |
49 | $res = $this->oPclZip->add(...$params);
50 | if ($res == 0) {
51 | throw new \Exception('Error zipping files : ' . $this->oPclZip->errorInfo(true));
52 | }
53 | unlink($this->tmpDir . '/' . $pathData['basename']);
54 |
55 | return $this;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/tests/Common/Tests/AutoloaderTest.php:
--------------------------------------------------------------------------------
1 | assertContains(
35 | ['PhpOffice\\Common\\Autoloader', 'autoload'],
36 | spl_autoload_functions()
37 | );
38 | }
39 |
40 | /**
41 | * Autoload
42 | */
43 | public function testAutoload(): void
44 | {
45 | $declared = get_declared_classes();
46 | $declaredCount = count($declared);
47 | Autoloader::autoload('Foo');
48 | $this->assertEquals(
49 | $declaredCount,
50 | count(get_declared_classes()),
51 | 'PhpOffice\\Common\\Autoloader::autoload() is trying to load ' .
52 | 'classes outside of the PhpOffice\\Common namespace'
53 | );
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/Common/Autoloader.php:
--------------------------------------------------------------------------------
1 | assertEquals(16, Font::fontSizeToPixels());
34 | $this->assertEquals((16 / 12) * $value, Font::fontSizeToPixels($value));
35 | $this->assertEquals(96, Font::inchSizeToPixels());
36 | $this->assertEquals(96 * $value, Font::inchSizeToPixels($value));
37 | $this->assertEquals(37.795275591, Font::centimeterSizeToPixels());
38 | $this->assertEquals(37.795275591 * $value, Font::centimeterSizeToPixels($value));
39 | $this->assertEquals($value / 2.54 * 1440, Font::centimeterSizeToTwips($value));
40 | $this->assertEquals($value * 1440, Font::inchSizeToTwips($value));
41 | $this->assertEquals($value / 96 * 1440, Font::pixelSizeToTwips($value));
42 | $this->assertEquals($value / 72 * 1440, Font::pointSizeToTwips($value));
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/tests/bootstrap.php:
--------------------------------------------------------------------------------
1 | assertEquals('M795/MAlmGU8RIsY9Q9uDLHC7bk=', $hashPassword);
43 | }
44 |
45 | /**
46 | * Test that a password can be hashed with a custom salt
47 | */
48 | public function testEncodePasswordWithSalt(): void
49 | {
50 | // Given
51 | $password = 'test';
52 | $salt = base64_decode('uq81pJRRGFIY5U+E9gt8tA==');
53 |
54 | // When
55 | $hashPassword = PasswordEncoder::hashPassword($password, PasswordEncoder::ALGORITHM_SHA_1, $salt);
56 |
57 | // Then
58 | $this->assertEquals('QiDOcpia1YzSVJPiKPwWebl9p/0=', $hashPassword);
59 | }
60 |
61 | /**
62 | * Test that the encoder falls back on SHA-1 if a non supported algorithm is given
63 | */
64 | public function testDefaultsToSha1IfUnsupportedAlgorithm(): void
65 | {
66 | // Given
67 | $password = 'test';
68 | $salt = base64_decode('uq81pJRRGFIY5U+E9gt8tA==');
69 |
70 | // When
71 | $hashPassword = PasswordEncoder::hashPassword($password, PasswordEncoder::ALGORITHM_MAC, $salt);
72 |
73 | // Then
74 | $this->assertEquals('QiDOcpia1YzSVJPiKPwWebl9p/0=', $hashPassword);
75 | }
76 |
77 | /**
78 | * Test that the encoder falls back on SHA-1 if a non supported algorithm is given
79 | */
80 | public function testEncodePasswordWithNullAsciiCodeInPassword(): void
81 | {
82 | // Given
83 | $password = 'test' . chr(0);
84 | $salt = base64_decode('uq81pJRRGFIY5U+E9gt8tA==');
85 |
86 | // When
87 | $hashPassword = PasswordEncoder::hashPassword($password, PasswordEncoder::ALGORITHM_MAC, $salt, 1);
88 |
89 | // Then
90 | $this->assertEquals('rDV9sgdDsztoCQlvRCb1lF2wxNg=', $hashPassword);
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/src/Common/Font.php:
--------------------------------------------------------------------------------
1 | zipTest = tempnam(sys_get_temp_dir(), 'PhpOfficeCommon');
28 | copy($pathResources . 'Sample_01_Simple.pptx', $this->zipTest);
29 | }
30 |
31 | public function tearDown(): void
32 | {
33 | parent::tearDown();
34 |
35 | if (is_file($this->zipTest)) {
36 | unlink($this->zipTest);
37 | }
38 | }
39 |
40 | public function testOpen(): void
41 | {
42 | $adapter = $this->createAdapter();
43 | $this->assertSame($adapter, $adapter->open($this->zipTest));
44 | }
45 |
46 | public function testClose(): void
47 | {
48 | $adapter = $this->createAdapter();
49 | $adapter->open($this->zipTest);
50 | $this->assertSame($adapter, $adapter->close());
51 | }
52 |
53 | public function testAddFromStringWithCompression(): void
54 | {
55 | $expectedPath = 'file.png';
56 | $expectedContent = file_get_contents(
57 | PHPOFFICE_COMMON_TESTS_BASE_DIR
58 | . DIRECTORY_SEPARATOR . 'resources'
59 | . DIRECTORY_SEPARATOR . 'images'
60 | . DIRECTORY_SEPARATOR . 'PHPPowerPointLogo.png'
61 | );
62 |
63 | $adapter = $this->createAdapter();
64 | $adapter->open($this->zipTest);
65 | $this->assertSame($adapter, $adapter->addFromString($expectedPath, $expectedContent, true));
66 | $adapter->close();
67 |
68 | $this->assertTrue(TestHelperZip::assertFileExists($this->zipTest, $expectedPath));
69 | $this->assertTrue(TestHelperZip::assertFileIsCompressed($this->zipTest, $expectedPath));
70 | $this->assertTrue(TestHelperZip::assertFileContent($this->zipTest, $expectedPath, $expectedContent));
71 | }
72 |
73 | public function testAddFromStringWithNoCompression(): void
74 | {
75 | $expectedPath = 'file.png';
76 | $expectedContent = file_get_contents(
77 | PHPOFFICE_COMMON_TESTS_BASE_DIR
78 | . DIRECTORY_SEPARATOR . 'resources'
79 | . DIRECTORY_SEPARATOR . 'images'
80 | . DIRECTORY_SEPARATOR . 'PHPPowerPointLogo.png'
81 | );
82 |
83 | $adapter = $this->createAdapter();
84 | $adapter->open($this->zipTest);
85 | $this->assertSame($adapter, $adapter->addFromString($expectedPath, $expectedContent, false));
86 | $adapter->close();
87 |
88 | $this->assertTrue(TestHelperZip::assertFileExists($this->zipTest, $expectedPath));
89 | $this->assertFalse(TestHelperZip::assertFileIsCompressed($this->zipTest, $expectedPath));
90 | $this->assertTrue(TestHelperZip::assertFileContent($this->zipTest, $expectedPath, $expectedContent));
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/tests/Common/Tests/TextTest.php:
--------------------------------------------------------------------------------
1 | assertEquals('', Text::controlCharacterPHP2OOXML());
34 | $this->assertEquals('aeiou', Text::controlCharacterPHP2OOXML('aeiou'));
35 | $this->assertEquals('àéîöù', Text::controlCharacterPHP2OOXML('àéîöù'));
36 |
37 | $value = rand(0, 8);
38 | $this->assertEquals(
39 | '_x' . sprintf('%04s', strtoupper(dechex($value))) . '_',
40 | Text::controlCharacterPHP2OOXML(chr($value))
41 | );
42 | }
43 |
44 | public function testControlCharactersOOXML2PHP(): void
45 | {
46 | $this->assertEquals('', Text::controlCharacterOOXML2PHP(''));
47 | $this->assertEquals(chr(0x08), Text::controlCharacterOOXML2PHP('_x0008_'));
48 | }
49 |
50 | public function testNumberFormat(): void
51 | {
52 | $this->assertEquals('2.1', Text::numberFormat(2.06, 1));
53 | $this->assertEquals('2.1', Text::numberFormat(2.12, 1));
54 | $this->assertEquals('1234.0', Text::numberFormat(1234, 1));
55 | }
56 |
57 | public function testChr(): void
58 | {
59 | $this->assertEquals('A', Text::chr(65));
60 | $this->assertEquals('A', Text::chr(0x41));
61 | $this->assertEquals('é', Text::chr(233));
62 | $this->assertEquals('é', Text::chr(0xE9));
63 | $this->assertEquals('⼳', Text::chr(12083));
64 | $this->assertEquals('⼳', Text::chr(0x2F33));
65 | $this->assertEquals('🌃', Text::chr(127747));
66 | $this->assertEquals('🌃', Text::chr(0x1F303));
67 | $this->assertEquals('', Text::chr(2097152));
68 | }
69 |
70 | public function testIsUTF8(): void
71 | {
72 | $this->assertTrue(Text::isUTF8(''));
73 | $this->assertTrue(Text::isUTF8('éééé'));
74 | $this->assertFalse(Text::isUTF8(utf8_decode('éééé')));
75 | }
76 |
77 | public function testToUtf8(): void
78 | {
79 | $this->assertNull(Text::toUTF8(null));
80 | $this->assertEquals('eeee', Text::toUTF8('eeee'));
81 | $this->assertEquals('éééé', Text::toUTF8('éééé'));
82 | }
83 |
84 | /**
85 | * Test unicode conversion
86 | */
87 | public function testToUnicode(): void
88 | {
89 | $this->assertEquals('a', Text::toUnicode('a'));
90 | $this->assertEquals('\uc0{\u8364}', Text::toUnicode('€'));
91 | $this->assertEquals('\uc0{\u233}', Text::toUnicode('é'));
92 | }
93 |
94 | /**
95 | * Test remove underscore prefix
96 | */
97 | public function testRemoveUnderscorePrefix(): void
98 | {
99 | $this->assertEquals('item', Text::removeUnderscorePrefix('_item'));
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/.github/workflows/php.yml:
--------------------------------------------------------------------------------
1 | name: PHPOffice\Common
2 | on: [push, pull_request]
3 | jobs:
4 | php-cs-fixer:
5 | name: PHP CS Fixer
6 | runs-on: ubuntu-latest
7 | steps:
8 | - name: Setup PHP
9 | uses: shivammathur/setup-php@v2
10 | with:
11 | php-version: '7.4'
12 | extensions: mbstring, intl, gd, xml, dom, json, fileinfo, curl, zip, iconv
13 | - uses: actions/checkout@v2
14 |
15 | - name: Validate composer config
16 | run: composer validate --strict
17 |
18 | - name: Composer Install
19 | run: composer global require friendsofphp/php-cs-fixer
20 |
21 | - name: Add environment path
22 | run: export PATH="$PATH:$HOME/.composer/vendor/bin"
23 |
24 | - name: Run PHPCSFixer
25 | run: php-cs-fixer fix --dry-run --diff
26 |
27 | phpmd:
28 | name: PHP Mess Detector
29 | runs-on: ubuntu-latest
30 | steps:
31 | - name: Setup PHP
32 | uses: shivammathur/setup-php@v2
33 | with:
34 | php-version: '7.4'
35 | extensions: gd, xml, zip
36 | - uses: actions/checkout@v2
37 |
38 | - name: Composer Install
39 | run: composer install --ansi --prefer-dist --no-interaction --no-progress
40 |
41 | - name: Run phpmd
42 | run: ./vendor/bin/phpmd src/,tests/ text ./phpmd.xml.dist
43 |
44 | phpstan:
45 | name: PHP Static Analysis
46 | runs-on: ubuntu-latest
47 | strategy:
48 | fail-fast: false
49 | matrix:
50 | php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
51 | steps:
52 | - name: Setup PHP
53 | uses: shivammathur/setup-php@v2
54 | with:
55 | php-version: ${{ matrix.php }}
56 | extensions: gd, xml, zip
57 | - uses: actions/checkout@v2
58 |
59 | - name: Composer Install
60 | run: composer install --ansi --prefer-dist --no-interaction --no-progress
61 |
62 | - name: Run phpstan
63 | run: ./vendor/bin/phpstan analyse -c phpstan.neon.dist
64 |
65 | phpunit:
66 | name: PHPUnit
67 | runs-on: ubuntu-latest
68 | strategy:
69 | fail-fast: false
70 | matrix:
71 | php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
72 | steps:
73 | - name: Setup PHP
74 | uses: shivammathur/setup-php@v2
75 | with:
76 | php-version: ${{ matrix.php }}
77 | extensions: gd, xml, zip
78 | coverage: ${{ (matrix.php == '7.3') && 'xdebug' || 'none' }}
79 |
80 | - name: Generate Locale (for tests)
81 | run: sudo locale-gen de_DE.UTF-8 && sudo update-locale
82 |
83 | - uses: actions/checkout@v2
84 |
85 | - name: Composer Install
86 | run: composer install --ansi --prefer-dist --no-interaction --no-progress
87 |
88 | - name: Run phpunit
89 | if: matrix.php != '7.3'
90 | run: ./vendor/bin/phpunit -c phpunit.xml.dist --no-coverage
91 |
92 | - name: Run phpunit
93 | if: matrix.php == '7.3'
94 | run: ./vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover build/clover.xml
95 |
96 | - name: Upload coverage results to Coveralls
97 | if: matrix.php == '7.3'
98 | env:
99 | COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
100 | run: |
101 | wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.4.3/php-coveralls.phar
102 | chmod +x php-coveralls.phar
103 | php php-coveralls.phar --coverage_clover=build/clover.xml --json_path=build/coveralls-upload.json -vvv
104 |
--------------------------------------------------------------------------------
/tests/Common/Tests/FileTest.php:
--------------------------------------------------------------------------------
1 | assertTrue(File::fileExists($pathResources . 'images' . DIRECTORY_SEPARATOR . 'PHPPowerPointLogo.png'));
34 | $this->assertFalse(File::fileExists($pathResources . 'images' . DIRECTORY_SEPARATOR . 'PHPPowerPointLogo_404.png'));
35 | $this->assertTrue(File::fileExists('zip://' . $pathResources . 'files' . DIRECTORY_SEPARATOR . 'Sample_01_Simple.pptx#[Content_Types].xml'));
36 | $this->assertFalse(File::fileExists('zip://' . $pathResources . 'files' . DIRECTORY_SEPARATOR . 'Sample_01_Simple.pptx#404.xml'));
37 | $this->assertFalse(File::fileExists('zip://' . $pathResources . 'files' . DIRECTORY_SEPARATOR . '404.pptx#404.xml'));
38 |
39 | // Set a ZIP en ReadOnly Mode
40 | $zipTest = tempnam(sys_get_temp_dir(), 'PhpOfficeCommon');
41 | copy($pathResources . 'files' . DIRECTORY_SEPARATOR . 'Sample_01_Simple.pptx', $zipTest);
42 | chmod($zipTest, 333);
43 | $this->assertFalse(File::fileExists('zip://' . $zipTest));
44 | unlink($zipTest);
45 | }
46 |
47 | public function testGetFileContents(): void
48 | {
49 | $pathResources = PHPOFFICE_COMMON_TESTS_BASE_DIR . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR;
50 | $this->assertIsString(File::fileGetContents($pathResources . 'images' . DIRECTORY_SEPARATOR . 'PHPPowerPointLogo.png'));
51 | $this->assertNull(File::fileGetContents($pathResources . 'images' . DIRECTORY_SEPARATOR . 'PHPPowerPointLogo_404.png'));
52 | $this->assertIsString(File::fileGetContents('zip://' . $pathResources . 'files' . DIRECTORY_SEPARATOR . 'Sample_01_Simple.pptx#[Content_Types].xml'));
53 | $this->assertNull(File::fileGetContents('zip://' . $pathResources . 'files' . DIRECTORY_SEPARATOR . 'Sample_01_Simple.pptx#404.xml'));
54 | $this->assertNull(File::fileGetContents('zip://' . $pathResources . 'files' . DIRECTORY_SEPARATOR . '404.pptx#404.xml'));
55 | }
56 |
57 | public function testRealPath(): void
58 | {
59 | $pathFiles = PHPOFFICE_COMMON_TESTS_BASE_DIR . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
60 | $this->assertEquals($pathFiles . 'Sample_01_Simple.pptx', File::realpath($pathFiles . 'Sample_01_Simple.pptx'));
61 | $this->assertEquals(
62 | 'zip://' . $pathFiles . 'Sample_01_Simple.pptx#[Content_Types].xml',
63 | File::realpath('zip://' . $pathFiles . 'Sample_01_Simple.pptx#[Content_Types].xml')
64 | );
65 | $this->assertEquals('zip://' . $pathFiles . 'Sample_01_Simple.pptx#/[Content_Types].xml', File::realpath('zip://' . $pathFiles . 'Sample_01_Simple.pptx#/rels/../[Content_Types].xml'));
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/Common/File.php:
--------------------------------------------------------------------------------
1 | open($zipFile) === true) {
42 | $returnValue = ($zip->getFromName($archiveFile) !== false);
43 | $zip->close();
44 |
45 | return $returnValue;
46 | }
47 |
48 | return false;
49 | }
50 |
51 | // Regular file_exists
52 | return file_exists($pFilename);
53 | }
54 |
55 | /**
56 | * Returns the content of a file
57 | *
58 | * @param string $pFilename Filename
59 | *
60 | * @return string|null
61 | */
62 | public static function fileGetContents(string $pFilename): ?string
63 | {
64 | if (!self::fileExists($pFilename)) {
65 | return null;
66 | }
67 | if (strtolower(substr($pFilename, 0, 3)) == 'zip') {
68 | // Open ZIP file and verify if the file exists
69 | $zipFile = substr($pFilename, 6, strpos($pFilename, '#') - 6);
70 | $archiveFile = substr($pFilename, strpos($pFilename, '#') + 1);
71 |
72 | $zip = new \ZipArchive();
73 | if ($zip->open($zipFile) === true) {
74 | $returnValue = $zip->getFromName($archiveFile);
75 | $zip->close();
76 |
77 | return $returnValue;
78 | }
79 |
80 | return null;
81 | }
82 |
83 | // Regular file contents
84 | return file_get_contents($pFilename);
85 | }
86 |
87 | /**
88 | * Returns canonicalized absolute pathname, also for ZIP archives
89 | *
90 | * @param string $pFilename
91 | *
92 | * @return string
93 | */
94 | public static function realpath(string $pFilename): string
95 | {
96 | // Try using realpath()
97 | $returnValue = realpath($pFilename);
98 |
99 | // Found something?
100 | if (empty($returnValue)) {
101 | $pathArray = explode('/', $pFilename);
102 | while (in_array('..', $pathArray) && $pathArray[0] != '..') {
103 | $numPathArray = count($pathArray);
104 | for ($i = 0; $i < $numPathArray; ++$i) {
105 | if ($pathArray[$i] == '..' && $i > 0) {
106 | unset($pathArray[$i]);
107 | unset($pathArray[$i - 1]);
108 | break;
109 | }
110 | }
111 | }
112 | $returnValue = implode('/', $pathArray);
113 | }
114 |
115 | // Return
116 | return $returnValue;
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/tests/Common/Tests/_includes/XmlDocument.php:
--------------------------------------------------------------------------------
1 | path = realpath($path);
65 | }
66 |
67 | /**
68 | * Get DOM from file
69 | *
70 | * @param string $file
71 | *
72 | * @return \DOMDocument
73 | */
74 | public function getFileDom(string $file = 'word/document.xml'): \DOMDocument
75 | {
76 | if (null !== $this->dom && $file === $this->file) {
77 | return $this->dom;
78 | }
79 |
80 | $this->xpath = null;
81 | $this->file = $file;
82 |
83 | $file = $this->path . '/' . $file;
84 | $this->dom = new \DOMDocument();
85 | $this->dom->load($file);
86 |
87 | return $this->dom;
88 | }
89 |
90 | /**
91 | * Get node list
92 | *
93 | * @param string $path
94 | * @param string $file
95 | *
96 | * @return \DOMNodeList<\DOMElement>
97 | */
98 | public function getNodeList(string $path, string $file = 'word/document.xml'): \DOMNodeList
99 | {
100 | if ($this->dom === null || $file !== $this->file) {
101 | $this->getFileDom($file);
102 | }
103 |
104 | if (null === $this->xpath) {
105 | $this->xpath = new \DOMXpath($this->dom);
106 | }
107 |
108 | return $this->xpath->query($path);
109 | }
110 |
111 | /**
112 | * Get element
113 | *
114 | * @param string $path
115 | * @param string $file
116 | *
117 | * @return \DOMNode
118 | */
119 | public function getElement(string $path, string $file = 'word/document.xml'): \DOMNode
120 | {
121 | $elements = $this->getNodeList($path, $file);
122 |
123 | return $elements->item(0);
124 | }
125 |
126 | /**
127 | * Get file name
128 | *
129 | * @return string
130 | */
131 | public function getFile(): string
132 | {
133 | return $this->file;
134 | }
135 |
136 | /**
137 | * Get path
138 | *
139 | * @return string
140 | */
141 | public function getPath(): string
142 | {
143 | return $this->path;
144 | }
145 |
146 | /**
147 | * Get element attribute
148 | *
149 | * @param string $path
150 | * @param string $attribute
151 | * @param string $file
152 | *
153 | * @return string
154 | */
155 | public function getElementAttribute(string $path, string $attribute, string $file = 'word/document.xml'): string
156 | {
157 | $element = $this->getElement($path, $file);
158 |
159 | return $element instanceof \DOMElement ? $element->getAttribute($attribute) : '';
160 | }
161 |
162 | /**
163 | * Get element attribute
164 | *
165 | * @param string $path
166 | * @param string $attribute
167 | * @param string $file
168 | *
169 | * @return bool
170 | */
171 | public function attributeElementExists(string $path, string $attribute, string $file = 'word/document.xml'): bool
172 | {
173 | $element = $this->getElement($path, $file);
174 |
175 | return $element instanceof \DOMElement ? $element->hasAttribute($attribute) : false;
176 | }
177 |
178 | /**
179 | * Check if element exists
180 | *
181 | * @param string $path
182 | * @param string $file
183 | *
184 | * @return bool
185 | */
186 | public function elementExists(string $path, string $file = 'word/document.xml'): bool
187 | {
188 | $nodeList = $this->getNodeList($path, $file);
189 |
190 | return !($nodeList->length == 0);
191 | }
192 | }
193 |
--------------------------------------------------------------------------------
/tests/Common/Tests/DrawingTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(0, Drawing::degreesToAngle());
35 | $this->assertEquals((int) round($value * 60000), Drawing::degreesToAngle($value));
36 | $this->assertEquals(0, Drawing::angleToDegrees());
37 | $this->assertEquals(round($value / 60000), Drawing::angleToDegrees($value));
38 | }
39 |
40 | public function testInchesPoints(): void
41 | {
42 | $value = rand(1, 100);
43 |
44 | $this->assertEquals(0, Drawing::inchesToPoints(0));
45 | $this->assertEquals($value * 72, Drawing::inchesToPoints($value));
46 | $this->assertEquals($value / 100 * 72, Drawing::inchesToPoints($value / 100));
47 | }
48 |
49 | public function testPicasPoints(): void
50 | {
51 | $value = rand(1, 100);
52 |
53 | $this->assertEquals(0, Drawing::picasToPoints(0));
54 | $this->assertEquals($value * 12, Drawing::picasToPoints($value));
55 | $this->assertEquals($value / 100 * 12, Drawing::picasToPoints($value / 100));
56 | }
57 |
58 | public function testPixelsCentimeters(): void
59 | {
60 | $value = rand(1, 100);
61 |
62 | $this->assertEquals(0, Drawing::pixelsToCentimeters());
63 | $this->assertEquals($value / Drawing::DPI_96 * 2.54, Drawing::pixelsToCentimeters($value));
64 | $this->assertEquals(0, Drawing::centimetersToPixels());
65 | $this->assertEquals(round($value / 2.54 * Drawing::DPI_96), Drawing::centimetersToPixels($value));
66 | }
67 |
68 | public function testPixelsEMU(): void
69 | {
70 | $value = rand(1, 100);
71 |
72 | $this->assertEquals(0, Drawing::pixelsToEmu());
73 | $this->assertEquals($value * 9525, Drawing::pixelsToEmu($value));
74 | $this->assertEquals(0, Drawing::emuToPixels());
75 | $this->assertEquals($value / 9525, Drawing::emuToPixels($value));
76 | }
77 |
78 | public function testPixelsPoints(): void
79 | {
80 | $value = rand(1, 100);
81 |
82 | $this->assertEquals(0, Drawing::pixelsToPoints());
83 | $this->assertEquals($value * 0.75, Drawing::pixelsToPoints($value));
84 | $this->assertEquals(0, Drawing::pointsToPixels());
85 | $this->assertEquals($value / 0.75, Drawing::pointsToPixels($value));
86 | }
87 |
88 | public function testPointsCentimeters(): void
89 | {
90 | $value = rand(1, 100);
91 |
92 | $this->assertEquals(0, Drawing::pointsToCentimeters());
93 | $this->assertEquals($value / 0.75 / Drawing::DPI_96 * 2.54, Drawing::pointsToCentimeters($value));
94 | }
95 |
96 | public function testPointsEmu(): void
97 | {
98 | $value = rand(1, 100);
99 |
100 | $this->assertEquals(0, Drawing::pointsToEmu());
101 | $this->assertEquals(round($value / 0.75 * 9525), Drawing::pointsToEmu($value));
102 | }
103 |
104 | public function testCentimetersPoints(): void
105 | {
106 | $this->assertEquals(0, Drawing::centimetersToPoints());
107 | $this->assertEquals(28.346456692913385, Drawing::centimetersToPoints(1));
108 | $this->assertEquals(31.181102362204722, Drawing::centimetersToPoints(1.1));
109 | }
110 |
111 | public function testTwips(): void
112 | {
113 | $value = rand(1, 100);
114 |
115 | // Centimeters
116 | $this->assertEquals(0, Drawing::centimetersToTwips());
117 | $this->assertEquals($value * 566.928, Drawing::centimetersToTwips($value));
118 |
119 | $this->assertEquals(0, Drawing::twipsToCentimeters());
120 | $this->assertEquals($value / 566.928, Drawing::twipsToCentimeters($value));
121 |
122 | // Inches
123 | $this->assertEquals(0, Drawing::inchesToTwips());
124 | $this->assertEquals($value * 1440, Drawing::inchesToTwips($value));
125 |
126 | $this->assertEquals(0, Drawing::twipsToInches());
127 | $this->assertEquals($value / 1440, Drawing::twipsToInches($value));
128 |
129 | // Pixels
130 | $this->assertEquals(0, Drawing::twipsToPixels());
131 | $this->assertEquals(round($value / 15), Drawing::twipsToPixels($value));
132 | }
133 |
134 | public function testHTML(): void
135 | {
136 | $this->assertNull(Drawing::htmlToRGB('0'));
137 | $this->assertNull(Drawing::htmlToRGB('00'));
138 | $this->assertNull(Drawing::htmlToRGB('0000'));
139 | $this->assertNull(Drawing::htmlToRGB('00000'));
140 |
141 | $this->assertIsArray(Drawing::htmlToRGB('ABCDEF'));
142 | $this->assertCount(3, Drawing::htmlToRGB('ABCDEF'));
143 | $this->assertEquals([0xAB, 0xCD, 0xEF], Drawing::htmlToRGB('ABCDEF'));
144 | $this->assertEquals([0xAB, 0xCD, 0xEF], Drawing::htmlToRGB('#ABCDEF'));
145 | $this->assertEquals([0xAA, 0xBB, 0xCC], Drawing::htmlToRGB('ABC'));
146 | $this->assertEquals([0xAA, 0xBB, 0xCC], Drawing::htmlToRGB('#ABC'));
147 | }
148 | }
149 |
--------------------------------------------------------------------------------
/tests/Common/Tests/XMLReaderTest.php:
--------------------------------------------------------------------------------
1 | getDomFromString('AAA');
39 |
40 | $this->assertTrue($reader->elementExists('/element/child'));
41 | $this->assertEquals('AAA', $reader->getElement('/element/child')->textContent);
42 | $this->assertEquals('AAA', $reader->getValue('/element/child'));
43 | $this->assertEquals('test', $reader->getAttribute('attr', $reader->getElement('/element')));
44 | $this->assertEquals('subtest', $reader->getAttribute('attr', $reader->getElement('/element'), 'child'));
45 | }
46 |
47 | /**
48 | * Test reading XML from zip
49 | */
50 | public function testDomFromZip(): void
51 | {
52 | $pathResources = PHPOFFICE_COMMON_TESTS_BASE_DIR . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
53 |
54 | $reader = new XMLReader();
55 | $this->assertInstanceOf(\DOMDocument::class, $reader->getDomFromZip($pathResources . 'reader.zip', 'test.xml'));
56 |
57 | $this->assertTrue($reader->elementExists('/element/child'));
58 |
59 | $this->assertFalse($reader->getDomFromZip($pathResources . 'reader.zip', 'non_existing_xml_file.xml'));
60 | }
61 |
62 | /**
63 | * Test reading XML from zip
64 | */
65 | public function testDomFromZipWithSharepointPath(): void
66 | {
67 | $pathResources = PHPOFFICE_COMMON_TESTS_BASE_DIR . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
68 |
69 | $reader = new XMLReader();
70 | $this->assertInstanceOf(\DOMDocument::class, $reader->getDomFromZip($pathResources . 'reader.zip', '/test.xml'));
71 | }
72 |
73 | /**
74 | * Test that read from non existing archive throws exception
75 | */
76 | public function testThrowsExceptionOnNonExistingArchive(): void
77 | {
78 | $this->expectException(\Exception::class);
79 | $this->expectExceptionMessage('Cannot find archive file.');
80 |
81 | $pathResources = PHPOFFICE_COMMON_TESTS_BASE_DIR . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
82 |
83 | $reader = new XMLReader();
84 | $reader->getDomFromZip($pathResources . 'readers.zip', 'test.xml');
85 | }
86 |
87 | /**
88 | * Test elements count
89 | */
90 | public function testCountElements(): void
91 | {
92 | $reader = new XMLReader();
93 | $reader->getDomFromString('AAABBB');
94 |
95 | $this->assertEquals(2, $reader->countElements('/element/child'));
96 | }
97 |
98 | /**
99 | * Test read non existing elements
100 | */
101 | public function testReturnNullOnNonExistingNode(): void
102 | {
103 | $reader = new XMLReader();
104 | $this->assertCount(0, $reader->getElements('/element/children'));
105 | $reader->getDomFromString('AAA');
106 |
107 | $this->assertNull($reader->getElement('/element/children'));
108 | $this->assertNull($reader->getValue('/element/children'));
109 | }
110 |
111 | /**
112 | * Test that xpath fails if custom namespace is not registered
113 | */
114 | public function testShouldThrowExceptionIfNamespaceIsNotKnown(): void
115 | {
116 | $reader = new XMLReader();
117 | $reader->getDomFromString('AAA');
118 | $reader->registerNamespace('test', 'http://phpword.com/my/custom/namespace');
119 |
120 | $this->assertTrue($reader->elementExists('/element/test:child'));
121 | $this->assertEquals('AAA', $reader->getElement('/element/test:child')->textContent);
122 | }
123 |
124 | /**
125 | * Test reading XML with manually registered namespace
126 | */
127 | public function testShouldParseXmlWithCustomNamespace(): void
128 | {
129 | $reader = new XMLReader();
130 | $reader->getDomFromString('AAA');
131 | $reader->registerNamespace('test', 'http://phpword.com/my/custom/namespace');
132 |
133 | $this->assertTrue($reader->elementExists('/element/test:child'));
134 | $this->assertEquals('AAA', $reader->getElement('/element/test:child')->textContent);
135 | }
136 |
137 | /**
138 | * Test that xpath fails if custom namespace is not registered
139 | */
140 | public function testShouldThowExceptionIfTryingToRegisterNamespaceBeforeReadingDoc(): void
141 | {
142 | $this->expectException(\InvalidArgumentException::class);
143 | $this->expectExceptionMessage('Dom needs to be loaded before registering a namespace');
144 |
145 | $reader = new XMLReader();
146 | $reader->registerNamespace('test', 'http://phpword.com/my/custom/namespace');
147 | }
148 | }
149 |
--------------------------------------------------------------------------------
/src/Common/XMLWriter.php:
--------------------------------------------------------------------------------
1 | openMemory();
62 | } else {
63 | if ($pTemporaryStorageDir && !is_dir($pTemporaryStorageDir)) {
64 | $pTemporaryStorageDir = sys_get_temp_dir();
65 | }
66 | // Create temporary filename
67 | $this->tempFileName = @tempnam($pTemporaryStorageDir, 'xml');
68 |
69 | // Open storage
70 | $this->openUri($this->tempFileName);
71 | }
72 |
73 | if ($compatibility) {
74 | $this->setIndent(false);
75 | $this->setIndentString('');
76 | } else {
77 | $this->setIndent(true);
78 | $this->setIndentString(' ');
79 | }
80 | }
81 |
82 | /**
83 | * Destructor
84 | */
85 | public function __destruct()
86 | {
87 | // Unlink temporary files
88 | if (empty($this->tempFileName)) {
89 | return;
90 | }
91 | if (PHP_OS != 'WINNT' && @unlink($this->tempFileName) === false) {
92 | throw new \Exception('The file ' . $this->tempFileName . ' could not be deleted.');
93 | }
94 | }
95 |
96 | /**
97 | * Get written data
98 | *
99 | * @return string
100 | */
101 | public function getData()
102 | {
103 | if ($this->tempFileName == '') {
104 | return $this->outputMemory(true);
105 | }
106 |
107 | $this->flush();
108 |
109 | return file_get_contents($this->tempFileName);
110 | }
111 |
112 | /**
113 | * Write simple element and attribute(s) block
114 | *
115 | * There are two options:
116 | * 1. If the `$attributes` is an array, then it's an associative array of attributes
117 | * 2. If not, then it's a simple attribute-value pair
118 | *
119 | * @param string $element
120 | * @param string|array $attributes
121 | * @param string $value
122 | *
123 | * @return void
124 | */
125 | public function writeElementBlock(string $element, $attributes, ?string $value = null)
126 | {
127 | $this->startElement($element);
128 | if (!is_array($attributes)) {
129 | $attributes = [$attributes => $value];
130 | }
131 | foreach ($attributes as $attribute => $value) {
132 | $this->writeAttribute($attribute, $value);
133 | }
134 | $this->endElement();
135 | }
136 |
137 | /**
138 | * Write element if ...
139 | *
140 | * @param bool $condition
141 | * @param string $element
142 | * @param string|null $attribute
143 | * @param mixed $value
144 | *
145 | * @return void
146 | */
147 | public function writeElementIf(bool $condition, string $element, ?string $attribute = null, $value = null)
148 | {
149 | if ($condition) {
150 | if (is_null($attribute)) {
151 | $this->writeElement($element, $value);
152 | } else {
153 | $this->startElement($element);
154 | $this->writeAttribute($attribute, $value);
155 | $this->endElement();
156 | }
157 | }
158 | }
159 |
160 | /**
161 | * Write attribute if ...
162 | *
163 | * @param bool $condition
164 | * @param string $attribute
165 | * @param mixed $value
166 | *
167 | * @return void
168 | */
169 | public function writeAttributeIf(bool $condition, string $attribute, $value)
170 | {
171 | if ($condition) {
172 | $this->writeAttribute($attribute, $value);
173 | }
174 | }
175 |
176 | /**
177 | * @param string $name
178 | * @param mixed $value
179 | *
180 | * @return bool
181 | */
182 | public function writeAttribute($name, $value): bool
183 | {
184 | if (is_float($value)) {
185 | $value = json_encode($value);
186 | }
187 |
188 | return parent::writeAttribute($name, $value ?? '');
189 | }
190 | }
191 |
--------------------------------------------------------------------------------
/tests/Common/Tests/XMLWriterTest.php:
--------------------------------------------------------------------------------
1 | startElement('element');
36 | $object->text('AAA');
37 | $object->endElement();
38 | $this->assertEquals('AAA' . chr(10), $object->getData());
39 |
40 | // Disk
41 | $object = new XMLWriter(XMLWriter::STORAGE_DISK);
42 | $object->startElement('element');
43 | $object->text('BBB');
44 | $object->endElement();
45 | $this->assertEquals('BBB' . chr(10), $object->getData());
46 | }
47 |
48 | public function testConstructCompatibility(): void
49 | {
50 | $object = new XMLWriter(XMLWriter::STORAGE_MEMORY, null, false);
51 | $object->startElement('element');
52 | $object->startElement('sub');
53 | $object->text('CCC');
54 | $object->endElement();
55 | $object->endElement();
56 | $this->assertEquals(
57 | '' . PHP_EOL . ' CCC' . PHP_EOL . '' . PHP_EOL,
58 | $object->getData()
59 | );
60 | $object = new XMLWriter(XMLWriter::STORAGE_MEMORY, null, true);
61 | $object->startElement('element');
62 | $object->startElement('sub');
63 | $object->text('CCC');
64 | $object->endElement();
65 | $object->endElement();
66 | $this->assertEquals(
67 | 'CCC',
68 | $object->getData()
69 | );
70 | }
71 |
72 | public function testWriteAttribute(): void
73 | {
74 | $xmlWriter = new XMLWriter();
75 | $xmlWriter->startElement('element');
76 | $xmlWriter->writeAttribute('name', 'value');
77 | $xmlWriter->endElement();
78 |
79 | $this->assertSame('' . chr(10), $xmlWriter->getData());
80 | }
81 |
82 | public function testWriteAttributeIf(): void
83 | {
84 | $xmlWriter = new XMLWriter();
85 | $xmlWriter->startElement('element');
86 | $xmlWriter->writeAttributeIf(true, 'name', 'value');
87 | $xmlWriter->endElement();
88 |
89 | $this->assertSame('' . chr(10), $xmlWriter->getData());
90 |
91 | $xmlWriter = new XMLWriter();
92 | $xmlWriter->startElement('element');
93 | $xmlWriter->writeAttributeIf(false, 'name', 'value');
94 | $xmlWriter->endElement();
95 |
96 | $this->assertSame('' . chr(10), $xmlWriter->getData());
97 | }
98 |
99 | public function testWriteAttributeShouldWriteFloatValueLocaleIndependent(): void
100 | {
101 | $value = 1.2;
102 |
103 | $xmlWriter = new XMLWriter();
104 | $xmlWriter->startElement('element');
105 | $xmlWriter->writeAttribute('name', $value);
106 | $xmlWriter->endElement();
107 |
108 | // https://www.php.net/manual/en/language.types.string.php#language.types.string.casting
109 | // As of PHP 8.0.0, the decimal point character is always ..
110 | // Prior to PHP 8.0.0, the decimal point character is defined in the script's locale (category LC_NUMERIC).
111 | setlocale(LC_NUMERIC, 'de_DE.UTF-8', 'de');
112 | if (PHP_VERSION_ID > 80000) {
113 | $this->assertSame('1.2', (string) $value);
114 | } else {
115 | $this->assertSame('1,2', (string) $value);
116 | }
117 | $this->assertSame('' . chr(10), $xmlWriter->getData());
118 | }
119 |
120 | public function testWriteElementBlock(): void
121 | {
122 | $xmlWriter = new XMLWriter();
123 | $xmlWriter->writeElementBlock('element', 'name');
124 |
125 | $this->assertSame('' . chr(10), $xmlWriter->getData());
126 |
127 | $xmlWriter = new XMLWriter();
128 | $xmlWriter->writeElementBlock('element', 'name', 'value');
129 |
130 | $this->assertSame('' . chr(10), $xmlWriter->getData());
131 |
132 | $xmlWriter = new XMLWriter();
133 | $xmlWriter->writeElementBlock('element', ['name' => 'value']);
134 |
135 | $this->assertSame('' . chr(10), $xmlWriter->getData());
136 |
137 | $xmlWriter = new XMLWriter();
138 | $xmlWriter->writeElementBlock('element', ['name' => 'value'], 'value2');
139 |
140 | $this->assertSame('' . chr(10), $xmlWriter->getData());
141 | }
142 |
143 | /**
144 | * @dataProvider dataProviderWriteElementIf
145 | */
146 | #[DataProvider('dataProviderWriteElementIf')]
147 | public function testWriteElementIf(bool $condition, ?string $attribute, ?string $value, string $expected): void
148 | {
149 | $xmlWriter = new XMLWriter();
150 | $xmlWriter->writeElementIf($condition, 'element', $attribute, $value);
151 |
152 | $this->assertSame($expected, $xmlWriter->getData());
153 | }
154 |
155 | /**
156 | * @return array>
157 | */
158 | public static function dataProviderWriteElementIf(): array
159 | {
160 | return [
161 | [
162 | false,
163 | null,
164 | null,
165 | '',
166 | ],
167 | [
168 | true,
169 | null,
170 | null,
171 | '' . chr(10),
172 | ],
173 | [
174 | true,
175 | 'attribute',
176 | null,
177 | '' . chr(10),
178 | ],
179 | [
180 | true,
181 | null,
182 | 'value',
183 | 'value' . chr(10),
184 | ],
185 | [
186 | true,
187 | 'attribute',
188 | 'value',
189 | '' . chr(10),
190 | ],
191 | ];
192 | }
193 | }
194 |
--------------------------------------------------------------------------------
/src/Common/XMLReader.php:
--------------------------------------------------------------------------------
1 | open($zipFile);
64 | $content = $zip->getFromName($xmlFile);
65 |
66 | // Files downloaded from Sharepoint are somehow different and fail on the leading slash.
67 | if ($content === false && substr($xmlFile, 0, 1) === '/') {
68 | $content = $zip->getFromName(substr($xmlFile, 1));
69 | }
70 |
71 | $zip->close();
72 |
73 | if ($content === false) {
74 | return false;
75 | }
76 |
77 | return $this->getDomFromString($content);
78 | }
79 |
80 | /**
81 | * Get DOMDocument from content string
82 | *
83 | * @param string $content
84 | *
85 | * @return \DOMDocument
86 | */
87 | public function getDomFromString(string $content)
88 | {
89 | $originalLibXMLEntityValue = false;
90 | if (\PHP_VERSION_ID < 80000) {
91 | $originalLibXMLEntityValue = libxml_disable_entity_loader(true);
92 | }
93 |
94 | $this->dom = new \DOMDocument();
95 | $this->dom->loadXML($content);
96 |
97 | if (\PHP_VERSION_ID < 80000) {
98 | libxml_disable_entity_loader($originalLibXMLEntityValue);
99 | }
100 |
101 | return $this->dom;
102 | }
103 |
104 | /**
105 | * Get elements
106 | *
107 | * @param string $path
108 | * @param \DOMElement $contextNode
109 | *
110 | * @return \DOMNodeList<\DOMElement>
111 | */
112 | public function getElements(string $path, ?\DOMElement $contextNode = null)
113 | {
114 | if ($this->dom === null) {
115 | return new \DOMNodeList();
116 | }
117 | if ($this->xpath === null) {
118 | $this->xpath = new \DOMXpath($this->dom);
119 | }
120 |
121 | if (is_null($contextNode)) {
122 | return $this->xpath->query($path);
123 | }
124 |
125 | return $this->xpath->query($path, $contextNode);
126 | }
127 |
128 | /**
129 | * Registers the namespace with the DOMXPath object
130 | *
131 | * @param string $prefix The prefix
132 | * @param string $namespaceURI The URI of the namespace
133 | *
134 | * @return bool true on success or false on failure
135 | *
136 | * @throws \InvalidArgumentException If called before having loaded the DOM document
137 | */
138 | public function registerNamespace($prefix, $namespaceURI)
139 | {
140 | if ($this->dom === null) {
141 | throw new \InvalidArgumentException('Dom needs to be loaded before registering a namespace');
142 | }
143 | if ($this->xpath === null) {
144 | $this->xpath = new \DOMXpath($this->dom);
145 | }
146 |
147 | return $this->xpath->registerNamespace($prefix, $namespaceURI);
148 | }
149 |
150 | /**
151 | * Get element
152 | *
153 | * @param string $path
154 | * @param \DOMElement $contextNode
155 | *
156 | * @return \DOMElement|null
157 | */
158 | public function getElement($path, ?\DOMElement $contextNode = null): ?\DOMElement
159 | {
160 | $elements = $this->getElements($path, $contextNode);
161 | if ($elements->length > 0) {
162 | return $elements->item(0) instanceof \DOMElement ? $elements->item(0) : null;
163 | }
164 |
165 | return null;
166 | }
167 |
168 | /**
169 | * Get element attribute
170 | *
171 | * @param string $attribute
172 | * @param \DOMElement $contextNode
173 | * @param string $path
174 | *
175 | * @return string|null
176 | */
177 | public function getAttribute($attribute, ?\DOMElement $contextNode = null, ?string $path = null)
178 | {
179 | $return = null;
180 | if ($path !== null) {
181 | $elements = $this->getElements($path, $contextNode);
182 | if ($elements->length > 0) {
183 | /** @var \DOMElement $node Type hint */
184 | $node = $elements->item(0);
185 | $return = $node->getAttribute($attribute);
186 | }
187 | } else {
188 | if ($contextNode !== null) {
189 | $return = $contextNode->getAttribute($attribute);
190 | }
191 | }
192 |
193 | return ($return == '') ? null : $return;
194 | }
195 |
196 | /**
197 | * Get element value
198 | *
199 | * @param string $path
200 | * @param \DOMElement $contextNode
201 | *
202 | * @return string|null
203 | */
204 | public function getValue($path, ?\DOMElement $contextNode = null)
205 | {
206 | $elements = $this->getElements($path, $contextNode);
207 | if ($elements->length > 0) {
208 | return $elements->item(0)->nodeValue;
209 | }
210 |
211 | return null;
212 | }
213 |
214 | /**
215 | * Count elements
216 | *
217 | * @param string $path
218 | * @param \DOMElement $contextNode
219 | *
220 | * @return int
221 | */
222 | public function countElements($path, ?\DOMElement $contextNode = null)
223 | {
224 | $elements = $this->getElements($path, $contextNode);
225 |
226 | return $elements->length;
227 | }
228 |
229 | /**
230 | * Element exists
231 | *
232 | * @param string $path
233 | * @param \DOMElement $contextNode
234 | *
235 | * @return bool
236 | */
237 | public function elementExists($path, ?\DOMElement $contextNode = null)
238 | {
239 | return $this->getElements($path, $contextNode)->length > 0;
240 | }
241 | }
242 |
--------------------------------------------------------------------------------
/src/Common/Text.php:
--------------------------------------------------------------------------------
1 | )
56 | * element or in the shared string element.
57 | *
58 | * @param string $value Value to escape
59 | *
60 | * @return string
61 | */
62 | public static function controlCharacterPHP2OOXML(string $value = ''): string
63 | {
64 | if (empty(self::$controlCharacters)) {
65 | self::buildControlCharacters();
66 | }
67 |
68 | return str_replace(array_values(self::$controlCharacters), array_keys(self::$controlCharacters), $value);
69 | }
70 |
71 | /**
72 | * Return a number formatted for being integrated in xml files
73 | *
74 | * @param float $number
75 | * @param int $decimals
76 | *
77 | * @return string
78 | */
79 | public static function numberFormat(float $number, int $decimals): string
80 | {
81 | return number_format($number, $decimals, '.', '');
82 | }
83 |
84 | /**
85 | * @param int $dec
86 | *
87 | * @see http://stackoverflow.com/a/7153133/2235790
88 | *
89 | * @author velcrow
90 | *
91 | * @return string
92 | */
93 | public static function chr(int $dec): string
94 | {
95 | if ($dec <= 0x7F) {
96 | return chr($dec);
97 | }
98 | if ($dec <= 0x7FF) {
99 | return chr(($dec >> 6) + 192) . chr(($dec & 63) + 128);
100 | }
101 | if ($dec <= 0xFFFF) {
102 | return chr(($dec >> 12) + 224) . chr((($dec >> 6) & 63) + 128) . chr(($dec & 63) + 128);
103 | }
104 | if ($dec <= 0x1FFFFF) {
105 | return chr(($dec >> 18) + 240) . chr((($dec >> 12) & 63) + 128) . chr((($dec >> 6) & 63) + 128) . chr(($dec & 63) + 128);
106 | }
107 |
108 | return '';
109 | }
110 |
111 | /**
112 | * Convert from OpenXML escaped control character to PHP control character
113 | *
114 | * @param string $value Value to unescape
115 | *
116 | * @return string
117 | */
118 | public static function controlCharacterOOXML2PHP(string $value = ''): string
119 | {
120 | if (empty(self::$controlCharacters)) {
121 | self::buildControlCharacters();
122 | }
123 |
124 | return str_replace(array_keys(self::$controlCharacters), array_values(self::$controlCharacters), $value);
125 | }
126 |
127 | /**
128 | * Check if a string contains UTF-8 data
129 | *
130 | * @param string $value
131 | *
132 | * @return bool
133 | */
134 | public static function isUTF8(string $value = ''): bool
135 | {
136 | return is_string($value) && ($value === '' || preg_match('/^./su', $value) == 1);
137 | }
138 |
139 | /**
140 | * Return UTF8 encoded value
141 | *
142 | * @param string|null $value
143 | *
144 | * @return string|null
145 | */
146 | public static function toUTF8(?string $value = ''): ?string
147 | {
148 | if (!is_null($value) && !self::isUTF8($value)) {
149 | $value = utf8_encode($value);
150 | }
151 |
152 | return $value;
153 | }
154 |
155 | /**
156 | * Returns unicode from UTF8 text
157 | *
158 | * The function is splitted to reduce cyclomatic complexity
159 | *
160 | * @param string $text UTF8 text
161 | *
162 | * @return string Unicode text
163 | *
164 | * @since 0.11.0
165 | */
166 | public static function toUnicode(string $text): string
167 | {
168 | return self::unicodeToEntities(self::utf8ToUnicode($text));
169 | }
170 |
171 | /**
172 | * Returns unicode array from UTF8 text
173 | *
174 | * @param string $text UTF8 text
175 | *
176 | * @return array
177 | *
178 | * @since 0.11.0
179 | * @see http://www.randomchaos.com/documents/?source=php_and_unicode
180 | */
181 | public static function utf8ToUnicode(string $text): array
182 | {
183 | $unicode = [];
184 | $values = [];
185 | $lookingFor = 1;
186 |
187 | // Gets unicode for each character
188 | for ($i = 0; $i < strlen($text); ++$i) {
189 | $thisValue = ord($text[$i]);
190 | if ($thisValue < 128) {
191 | $unicode[] = $thisValue;
192 | } else {
193 | if (count($values) == 0) {
194 | $lookingFor = $thisValue < 224 ? 2 : 3;
195 | }
196 | $values[] = $thisValue;
197 | if (count($values) == $lookingFor) {
198 | if ($lookingFor == 3) {
199 | $number = (($values[0] % 16) * 4096) + (($values[1] % 64) * 64) + ($values[2] % 64);
200 | } else {
201 | $number = (($values[0] % 32) * 64) + ($values[1] % 64);
202 | }
203 | $unicode[] = $number;
204 | $values = [];
205 | $lookingFor = 1;
206 | }
207 | }
208 | }
209 |
210 | return $unicode;
211 | }
212 |
213 | /**
214 | * Returns entites from unicode array
215 | *
216 | * @param array $unicode
217 | *
218 | * @return string
219 | *
220 | * @since 0.11.0
221 | * @see http://www.randomchaos.com/documents/?source=php_and_unicode
222 | */
223 | private static function unicodeToEntities(array $unicode): string
224 | {
225 | $entities = '';
226 |
227 | foreach ($unicode as $value) {
228 | if ($value != 65279) {
229 | $entities .= $value > 127 ? '\uc0{\u' . $value . '}' : chr($value);
230 | }
231 | }
232 |
233 | return $entities;
234 | }
235 |
236 | /**
237 | * Return name without underscore for < 0.10.0 variable name compatibility
238 | *
239 | * @param string|null $value
240 | *
241 | * @return string
242 | */
243 | public static function removeUnderscorePrefix(?string $value): string
244 | {
245 | if (!is_null($value)) {
246 | if (substr($value, 0, 1) == '_') {
247 | $value = substr($value, 1);
248 | }
249 | }
250 |
251 | return $value;
252 | }
253 | }
254 |
--------------------------------------------------------------------------------
/COPYING.LESSER:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 |
9 | This version of the GNU Lesser General Public License incorporates
10 | the terms and conditions of version 3 of the GNU General Public
11 | License, supplemented by the additional permissions listed below.
12 |
13 | 0. Additional Definitions.
14 |
15 | As used herein, "this License" refers to version 3 of the GNU Lesser
16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU
17 | General Public License.
18 |
19 | "The Library" refers to a covered work governed by this License,
20 | other than an Application or a Combined Work as defined below.
21 |
22 | An "Application" is any work that makes use of an interface provided
23 | by the Library, but which is not otherwise based on the Library.
24 | Defining a subclass of a class defined by the Library is deemed a mode
25 | of using an interface provided by the Library.
26 |
27 | A "Combined Work" is a work produced by combining or linking an
28 | Application with the Library. The particular version of the Library
29 | with which the Combined Work was made is also called the "Linked
30 | Version".
31 |
32 | The "Minimal Corresponding Source" for a Combined Work means the
33 | Corresponding Source for the Combined Work, excluding any source code
34 | for portions of the Combined Work that, considered in isolation, are
35 | based on the Application, and not on the Linked Version.
36 |
37 | The "Corresponding Application Code" for a Combined Work means the
38 | object code and/or source code for the Application, including any data
39 | and utility programs needed for reproducing the Combined Work from the
40 | Application, but excluding the System Libraries of the Combined Work.
41 |
42 | 1. Exception to Section 3 of the GNU GPL.
43 |
44 | You may convey a covered work under sections 3 and 4 of this License
45 | without being bound by section 3 of the GNU GPL.
46 |
47 | 2. Conveying Modified Versions.
48 |
49 | If you modify a copy of the Library, and, in your modifications, a
50 | facility refers to a function or data to be supplied by an Application
51 | that uses the facility (other than as an argument passed when the
52 | facility is invoked), then you may convey a copy of the modified
53 | version:
54 |
55 | a) under this License, provided that you make a good faith effort to
56 | ensure that, in the event an Application does not supply the
57 | function or data, the facility still operates, and performs
58 | whatever part of its purpose remains meaningful, or
59 |
60 | b) under the GNU GPL, with none of the additional permissions of
61 | this License applicable to that copy.
62 |
63 | 3. Object Code Incorporating Material from Library Header Files.
64 |
65 | The object code form of an Application may incorporate material from
66 | a header file that is part of the Library. You may convey such object
67 | code under terms of your choice, provided that, if the incorporated
68 | material is not limited to numerical parameters, data structure
69 | layouts and accessors, or small macros, inline functions and templates
70 | (ten or fewer lines in length), you do both of the following:
71 |
72 | a) Give prominent notice with each copy of the object code that the
73 | Library is used in it and that the Library and its use are
74 | covered by this License.
75 |
76 | b) Accompany the object code with a copy of the GNU GPL and this license
77 | document.
78 |
79 | 4. Combined Works.
80 |
81 | You may convey a Combined Work under terms of your choice that,
82 | taken together, effectively do not restrict modification of the
83 | portions of the Library contained in the Combined Work and reverse
84 | engineering for debugging such modifications, if you also do each of
85 | the following:
86 |
87 | a) Give prominent notice with each copy of the Combined Work that
88 | the Library is used in it and that the Library and its use are
89 | covered by this License.
90 |
91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 | document.
93 |
94 | c) For a Combined Work that displays copyright notices during
95 | execution, include the copyright notice for the Library among
96 | these notices, as well as a reference directing the user to the
97 | copies of the GNU GPL and this license document.
98 |
99 | d) Do one of the following:
100 |
101 | 0) Convey the Minimal Corresponding Source under the terms of this
102 | License, and the Corresponding Application Code in a form
103 | suitable for, and under terms that permit, the user to
104 | recombine or relink the Application with a modified version of
105 | the Linked Version to produce a modified Combined Work, in the
106 | manner specified by section 6 of the GNU GPL for conveying
107 | Corresponding Source.
108 |
109 | 1) Use a suitable shared library mechanism for linking with the
110 | Library. A suitable mechanism is one that (a) uses at run time
111 | a copy of the Library already present on the user's computer
112 | system, and (b) will operate properly with a modified version
113 | of the Library that is interface-compatible with the Linked
114 | Version.
115 |
116 | e) Provide Installation Information, but only if you would otherwise
117 | be required to provide such information under section 6 of the
118 | GNU GPL, and only to the extent that such information is
119 | necessary to install and execute a modified version of the
120 | Combined Work produced by recombining or relinking the
121 | Application with a modified version of the Linked Version. (If
122 | you use option 4d0, the Installation Information must accompany
123 | the Minimal Corresponding Source and Corresponding Application
124 | Code. If you use option 4d1, you must provide the Installation
125 | Information in the manner specified by section 6 of the GNU GPL
126 | for conveying Corresponding Source.)
127 |
128 | 5. Combined Libraries.
129 |
130 | You may place library facilities that are a work based on the
131 | Library side by side in a single library together with other library
132 | facilities that are not Applications and are not covered by this
133 | License, and convey such a combined library under terms of your
134 | choice, if you do both of the following:
135 |
136 | a) Accompany the combined library with a copy of the same work based
137 | on the Library, uncombined with any other library facilities,
138 | conveyed under the terms of this License.
139 |
140 | b) Give prominent notice with the combined library that part of it
141 | is a work based on the Library, and explaining where to find the
142 | accompanying uncombined form of the same work.
143 |
144 | 6. Revised Versions of the GNU Lesser General Public License.
145 |
146 | The Free Software Foundation may publish revised and/or new versions
147 | of the GNU Lesser General Public License from time to time. Such new
148 | versions will be similar in spirit to the present version, but may
149 | differ in detail to address new problems or concerns.
150 |
151 | Each version is given a distinguishing version number. If the
152 | Library as you received it specifies that a certain numbered version
153 | of the GNU Lesser General Public License "or any later version"
154 | applies to it, you have the option of following the terms and
155 | conditions either of that published version or of any later version
156 | published by the Free Software Foundation. If the Library as you
157 | received it does not specify a version number of the GNU Lesser
158 | General Public License, you may choose any version of the GNU Lesser
159 | General Public License ever published by the Free Software Foundation.
160 |
161 | If the Library as you received it specifies that a proxy can decide
162 | whether future versions of the GNU Lesser General Public License shall
163 | apply, that proxy's public statement of acceptance of any version is
164 | permanent authorization for you to choose that version for the
165 | Library.
166 |
--------------------------------------------------------------------------------
/src/Common/Drawing.php:
--------------------------------------------------------------------------------
1 | |null Value in RGB
128 | */
129 | public static function htmlToRGB(string $pValue): ?array
130 | {
131 | if ($pValue[0] == '#') {
132 | $pValue = substr($pValue, 1);
133 | }
134 |
135 | if (strlen($pValue) == 6) {
136 | list($colorR, $colorG, $colorB) = [$pValue[0] . $pValue[1], $pValue[2] . $pValue[3], $pValue[4] . $pValue[5]];
137 | } elseif (strlen($pValue) == 3) {
138 | list($colorR, $colorG, $colorB) = [$pValue[0] . $pValue[0], $pValue[1] . $pValue[1], $pValue[2] . $pValue[2]];
139 | } else {
140 | return null;
141 | }
142 |
143 | $colorR = hexdec($colorR);
144 | $colorG = hexdec($colorG);
145 | $colorB = hexdec($colorB);
146 |
147 | return [$colorR, $colorG, $colorB];
148 | }
149 |
150 | // Source : Inches
151 | /**
152 | * Convert inches to points
153 | *
154 | * @param float $pValue
155 | *
156 | * @return float
157 | */
158 | public static function inchesToPoints(float $pValue): float
159 | {
160 | return $pValue * 72;
161 | }
162 |
163 | /**
164 | * Convert inches width to twips
165 | *
166 | * @param int $pValue
167 | *
168 | * @return int
169 | */
170 | public static function inchesToTwips(int $pValue = 0): int
171 | {
172 | if ($pValue == 0) {
173 | return 0;
174 | }
175 |
176 | return $pValue * 1440;
177 | }
178 |
179 | // Source : Picas
180 | /**
181 | * Convert picas to points
182 | *
183 | * @param float $pValue
184 | *
185 | * @return float
186 | */
187 | public static function picasToPoints(float $pValue): float
188 | {
189 | return $pValue * 12;
190 | }
191 |
192 | // Source : Pixels
193 | /**
194 | * Convert pixels to centimeters
195 | *
196 | * @param int $pValue Value in pixels
197 | *
198 | * @return float
199 | */
200 | public static function pixelsToCentimeters(int $pValue = 0): float
201 | {
202 | // return $pValue * 0.028;
203 | return ($pValue / self::DPI_96) * 2.54;
204 | }
205 |
206 | /**
207 | * Convert pixels to EMU
208 | *
209 | * @param float $pValue Value in pixels
210 | *
211 | * @return float
212 | */
213 | public static function pixelsToEmu(float $pValue = 0): float
214 | {
215 | return $pValue * 9525;
216 | }
217 |
218 | /**
219 | * Convert pixels to points
220 | *
221 | * @param int $pValue Value in pixels
222 | *
223 | * @return float
224 | */
225 | public static function pixelsToPoints(int $pValue = 0): float
226 | {
227 | return $pValue * 0.75;
228 | }
229 |
230 | // Source : Points
231 | /**
232 | * Convert points width to centimeters
233 | *
234 | * @param float $pValue Value in points
235 | *
236 | * @return float
237 | */
238 | public static function pointsToCentimeters(float $pValue = 0): float
239 | {
240 | if ($pValue == 0) {
241 | return 0;
242 | }
243 |
244 | return (($pValue / 0.75) / self::DPI_96) * 2.54;
245 | }
246 |
247 | /**
248 | * Convert points to emu
249 | *
250 | * @param float $pValue
251 | *
252 | * @return int
253 | */
254 | public static function pointsToEmu(float $pValue = 0): int
255 | {
256 | if ($pValue == 0) {
257 | return 0;
258 | }
259 |
260 | return (int) round(($pValue / 0.75) * 9525);
261 | }
262 |
263 | /**
264 | * Convert points width to pixels
265 | *
266 | * @param float $pValue Value in points
267 | *
268 | * @return float
269 | */
270 | public static function pointsToPixels(float $pValue = 0): float
271 | {
272 | if ($pValue == 0) {
273 | return 0;
274 | }
275 |
276 | return $pValue / 0.75;
277 | }
278 |
279 | // Source : Twips
280 | /**
281 | * Convert twips width to centimeters
282 | *
283 | * @param int $pValue
284 | *
285 | * @return float
286 | */
287 | public static function twipsToCentimeters(int $pValue = 0): float
288 | {
289 | if ($pValue == 0) {
290 | return 0;
291 | }
292 |
293 | return $pValue / 566.928;
294 | }
295 |
296 | /**
297 | * Convert twips width to inches
298 | *
299 | * @param int $pValue
300 | *
301 | * @return float
302 | */
303 | public static function twipsToInches(int $pValue = 0): float
304 | {
305 | if ($pValue == 0) {
306 | return 0;
307 | }
308 |
309 | return $pValue / 1440;
310 | }
311 |
312 | /**
313 | * Convert twips width to pixels
314 | *
315 | * @param int $pValue
316 | *
317 | * @return float
318 | */
319 | public static function twipsToPixels(int $pValue = 0): float
320 | {
321 | if ($pValue == 0) {
322 | return 0;
323 | }
324 |
325 | return round($pValue / 15);
326 | }
327 | }
328 |
--------------------------------------------------------------------------------
/src/Common/Microsoft/PasswordEncoder.php:
--------------------------------------------------------------------------------
1 | >
42 | *
43 | * @see https://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.writeprotection.cryptographicalgorithmsid(v=office.14).aspx
44 | */
45 | private static $algorithmMapping = [
46 | self::ALGORITHM_MD2 => [1, 'md2'],
47 | self::ALGORITHM_MD4 => [2, 'md4'],
48 | self::ALGORITHM_MD5 => [3, 'md5'],
49 | self::ALGORITHM_SHA_1 => [4, 'sha1'],
50 | self::ALGORITHM_MAC => [5, ''], // 'mac' -> not possible with hash()
51 | self::ALGORITHM_RIPEMD => [6, 'ripemd'],
52 | self::ALGORITHM_RIPEMD_160 => [7, 'ripemd160'],
53 | self::ALGORITHM_HMAC => [9, ''], // 'hmac' -> not possible with hash()
54 | self::ALGORITHM_SHA_256 => [12, 'sha256'],
55 | self::ALGORITHM_SHA_384 => [13, 'sha384'],
56 | self::ALGORITHM_SHA_512 => [14, 'sha512'],
57 | ];
58 |
59 | /**
60 | * @var array
61 | */
62 | private static $initialCodeArray = [
63 | 0xE1F0,
64 | 0x1D0F,
65 | 0xCC9C,
66 | 0x84C0,
67 | 0x110C,
68 | 0x0E10,
69 | 0xF1CE,
70 | 0x313E,
71 | 0x1872,
72 | 0xE139,
73 | 0xD40F,
74 | 0x84F9,
75 | 0x280C,
76 | 0xA96A,
77 | 0x4EC3,
78 | ];
79 |
80 | /**
81 | * @var array>
82 | */
83 | private static $encryptionMatrix = [
84 | [0xAEFC, 0x4DD9, 0x9BB2, 0x2745, 0x4E8A, 0x9D14, 0x2A09],
85 | [0x7B61, 0xF6C2, 0xFDA5, 0xEB6B, 0xC6F7, 0x9DCF, 0x2BBF],
86 | [0x4563, 0x8AC6, 0x05AD, 0x0B5A, 0x16B4, 0x2D68, 0x5AD0],
87 | [0x0375, 0x06EA, 0x0DD4, 0x1BA8, 0x3750, 0x6EA0, 0xDD40],
88 | [0xD849, 0xA0B3, 0x5147, 0xA28E, 0x553D, 0xAA7A, 0x44D5],
89 | [0x6F45, 0xDE8A, 0xAD35, 0x4A4B, 0x9496, 0x390D, 0x721A],
90 | [0xEB23, 0xC667, 0x9CEF, 0x29FF, 0x53FE, 0xA7FC, 0x5FD9],
91 | [0x47D3, 0x8FA6, 0x0F6D, 0x1EDA, 0x3DB4, 0x7B68, 0xF6D0],
92 | [0xB861, 0x60E3, 0xC1C6, 0x93AD, 0x377B, 0x6EF6, 0xDDEC],
93 | [0x45A0, 0x8B40, 0x06A1, 0x0D42, 0x1A84, 0x3508, 0x6A10],
94 | [0xAA51, 0x4483, 0x8906, 0x022D, 0x045A, 0x08B4, 0x1168],
95 | [0x76B4, 0xED68, 0xCAF1, 0x85C3, 0x1BA7, 0x374E, 0x6E9C],
96 | [0x3730, 0x6E60, 0xDCC0, 0xA9A1, 0x4363, 0x86C6, 0x1DAD],
97 | [0x3331, 0x6662, 0xCCC4, 0x89A9, 0x0373, 0x06E6, 0x0DCC],
98 | [0x1021, 0x2042, 0x4084, 0x8108, 0x1231, 0x2462, 0x48C4],
99 | ];
100 |
101 | /**
102 | * @var int
103 | */
104 | private static $passwordMaxLength = 15;
105 |
106 | /**
107 | * Create a hashed password that MS Word will be able to work with
108 | *
109 | * @see https://blogs.msdn.microsoft.com/vsod/2010/04/05/how-to-set-the-editing-restrictions-in-word-using-open-xml-sdk-2-0/
110 | *
111 | * @param string $password
112 | * @param string $algorithmName
113 | * @param string $salt
114 | * @param int $spinCount
115 | *
116 | * @return string
117 | */
118 | public static function hashPassword(string $password, string $algorithmName = self::ALGORITHM_SHA_1, ?string $salt = null, int $spinCount = 10000)
119 | {
120 | $origEncoding = mb_internal_encoding();
121 | mb_internal_encoding('UTF-8');
122 |
123 | $password = mb_substr($password, 0, min(self::$passwordMaxLength, mb_strlen($password)));
124 |
125 | // Get the single-byte values by iterating through the Unicode characters of the truncated password.
126 | // For each character, if the low byte is not equal to 0, take it. Otherwise, take the high byte.
127 | $passUtf8 = mb_convert_encoding($password, 'UCS-2LE', 'UTF-8');
128 | $byteChars = [];
129 |
130 | for ($i = 0; $i < mb_strlen($password); ++$i) {
131 | $byteChars[$i] = ord(substr($passUtf8, $i * 2, 1));
132 |
133 | if ($byteChars[$i] == 0) {
134 | $byteChars[$i] = ord(substr($passUtf8, $i * 2 + 1, 1));
135 | }
136 | }
137 |
138 | // build low-order word and hig-order word and combine them
139 | $combinedKey = self::buildCombinedKey($byteChars);
140 | // build reversed hexadecimal string
141 | $hex = str_pad(strtoupper(dechex($combinedKey & 0xFFFFFFFF)), 8, '0', \STR_PAD_LEFT);
142 | $reversedHex = $hex[6] . $hex[7] . $hex[4] . $hex[5] . $hex[2] . $hex[3] . $hex[0] . $hex[1];
143 |
144 | $generatedKey = mb_convert_encoding($reversedHex, 'UCS-2LE', 'UTF-8');
145 |
146 | // Implementation Notes List:
147 | // Word requires that the initial hash of the password with the salt not be considered in the count.
148 | // The initial hash of salt + key is not included in the iteration count.
149 | $algorithm = self::getAlgorithm($algorithmName);
150 | $generatedKey = hash($algorithm, $salt . $generatedKey, true);
151 |
152 | for ($i = 0; $i < $spinCount; ++$i) {
153 | $generatedKey = hash($algorithm, $generatedKey . pack('CCCC', $i, $i >> 8, $i >> 16, $i >> 24), true);
154 | }
155 | $generatedKey = base64_encode($generatedKey);
156 |
157 | mb_internal_encoding($origEncoding);
158 |
159 | return $generatedKey;
160 | }
161 |
162 | /**
163 | * Get algorithm from self::$algorithmMapping
164 | *
165 | * @param string $algorithmName
166 | *
167 | * @return string
168 | */
169 | private static function getAlgorithm(string $algorithmName): string
170 | {
171 | $algorithm = self::$algorithmMapping[$algorithmName][1];
172 | if ($algorithm == '') {
173 | $algorithm = 'sha1';
174 | }
175 |
176 | return $algorithm;
177 | }
178 |
179 | /**
180 | * Returns the algorithm ID
181 | *
182 | * @param string $algorithmName
183 | *
184 | * @return int
185 | */
186 | public static function getAlgorithmId(string $algorithmName): int
187 | {
188 | return self::$algorithmMapping[$algorithmName][0];
189 | }
190 |
191 | /**
192 | * Build combined key from low-order word and high-order word
193 | *
194 | * @param array $byteChars byte array representation of password
195 | *
196 | * @return int
197 | */
198 | private static function buildCombinedKey(array $byteChars): int
199 | {
200 | $byteCharsLength = count($byteChars);
201 | // Compute the high-order word
202 | // Initialize from the initial code array (see above), depending on the passwords length.
203 | $highOrderWord = self::$initialCodeArray[$byteCharsLength - 1];
204 |
205 | // For each character in the password:
206 | // For every bit in the character, starting with the least significant and progressing to (but excluding)
207 | // the most significant, if the bit is set, XOR the key’s high-order word with the corresponding word from
208 | // the Encryption Matrix
209 | for ($i = 0; $i < $byteCharsLength; ++$i) {
210 | $tmp = self::$passwordMaxLength - $byteCharsLength + $i;
211 | $matrixRow = self::$encryptionMatrix[$tmp];
212 | for ($intBit = 0; $intBit < 7; ++$intBit) {
213 | if (($byteChars[$i] & (0x0001 << $intBit)) != 0) {
214 | $highOrderWord = ($highOrderWord ^ $matrixRow[$intBit]);
215 | }
216 | }
217 | }
218 |
219 | // Compute low-order word
220 | // Initialize with 0
221 | $lowOrderWord = 0;
222 | // For each character in the password, going backwards
223 | for ($i = $byteCharsLength - 1; $i >= 0; --$i) {
224 | // low-order word = (((low-order word SHR 14) AND 0x0001) OR (low-order word SHL 1) AND 0x7FFF)) XOR character
225 | $lowOrderWord = (((($lowOrderWord >> 14) & 0x0001) | (($lowOrderWord << 1) & 0x7FFF)) ^ $byteChars[$i]);
226 | }
227 | // Lastly, low-order word = (((low-order word SHR 14) AND 0x0001) OR (low-order word SHL 1) AND 0x7FFF)) XOR strPassword length XOR 0xCE4B.
228 | $lowOrderWord = (((($lowOrderWord >> 14) & 0x0001) | (($lowOrderWord << 1) & 0x7FFF)) ^ $byteCharsLength ^ 0xCE4B);
229 |
230 | // Combine the Low and High Order Word
231 | return self::int32(($highOrderWord << 16) + $lowOrderWord);
232 | }
233 |
234 | /**
235 | * Simulate behaviour of (signed) int32
236 | *
237 | * @codeCoverageIgnore
238 | *
239 | * @param int $value
240 | *
241 | * @return int
242 | */
243 | private static function int32($value)
244 | {
245 | $value = ($value & 0xFFFFFFFF);
246 |
247 | if ($value & 0x80000000) {
248 | $value = -((~$value & 0xFFFFFFFF) + 1);
249 | }
250 |
251 | return $value;
252 | }
253 | }
254 |
--------------------------------------------------------------------------------
/src/Common/Microsoft/OLERead.php:
--------------------------------------------------------------------------------
1 | >
87 | */
88 | public $props = [];
89 | /**
90 | * @var string|null
91 | */
92 | public $smallBlockChain;
93 | /**
94 | * @var string|null
95 | */
96 | public $bigBlockChain;
97 | /**
98 | * @var string|null
99 | */
100 | public $entry;
101 |
102 | /**
103 | * Read the file
104 | *
105 | * @param string $sFileName Filename
106 | *
107 | * @throws \Exception
108 | */
109 | public function read(string $sFileName): void
110 | {
111 | // Check if file exists and is readable
112 | if (!is_readable($sFileName)) {
113 | throw new \Exception('Could not open ' . $sFileName . ' for reading! File does not exist, or it is not readable.');
114 | }
115 |
116 | // Get the file identifier
117 | // Don't bother reading the whole file until we know it's a valid OLE file
118 | $this->data = file_get_contents($sFileName, false, null, 0, 8);
119 |
120 | // Check OLE identifier
121 | if ($this->data != self::IDENTIFIER_OLE) {
122 | throw new \Exception('The filename ' . $sFileName . ' is not recognised as an OLE file');
123 | }
124 |
125 | // Get the file data
126 | $this->data = file_get_contents($sFileName);
127 |
128 | // Total number of sectors used for the SAT
129 | $numBigBlkDepotBlks = self::getInt4d($this->data, self::NUM_BIG_BLOCK_DEPOT_BLOCKS_POS);
130 |
131 | // SecID of the first sector of the directory stream
132 | $rootStartBlock = self::getInt4d($this->data, self::ROOT_START_BLOCK_POS);
133 |
134 | // SecID of the first sector of the SSAT (or -2 if not extant)
135 | $sbdStartBlock = self::getInt4d($this->data, self::SMALL_BLOCK_DEPOT_BLOCK_POS);
136 |
137 | // SecID of the first sector of the MSAT (or -2 if no additional sectors are used)
138 | $extensionBlock = self::getInt4d($this->data, self::EXTENSION_BLOCK_POS);
139 |
140 | // Total number of sectors used by MSAT
141 | $numExtensionBlocks = self::getInt4d($this->data, self::NUM_EXTENSION_BLOCK_POS);
142 |
143 | $bigBlockDepotBlocks = [];
144 | $pos = self::BIG_BLOCK_DEPOT_BLOCKS_POS;
145 |
146 | $bbdBlocks = $numBigBlkDepotBlks;
147 |
148 | if ($numExtensionBlocks != 0) {
149 | $bbdBlocks = (self::BIG_BLOCK_SIZE - self::BIG_BLOCK_DEPOT_BLOCKS_POS) / 4;
150 | }
151 |
152 | for ($i = 0; $i < $bbdBlocks; ++$i) {
153 | $bigBlockDepotBlocks[$i] = self::getInt4d($this->data, $pos);
154 | $pos += 4;
155 | }
156 |
157 | for ($j = 0; $j < $numExtensionBlocks; ++$j) {
158 | $pos = ($extensionBlock + 1) * self::BIG_BLOCK_SIZE;
159 | $blocksToRead = min($numBigBlkDepotBlks - $bbdBlocks, self::BIG_BLOCK_SIZE / 4 - 1);
160 |
161 | for ($i = $bbdBlocks; $i < $bbdBlocks + $blocksToRead; ++$i) {
162 | $bigBlockDepotBlocks[$i] = self::getInt4d($this->data, $pos);
163 | $pos += 4;
164 | }
165 |
166 | $bbdBlocks += $blocksToRead;
167 | if ($bbdBlocks < $numBigBlkDepotBlks) {
168 | $extensionBlock = self::getInt4d($this->data, $pos);
169 | }
170 | }
171 |
172 | $this->bigBlockChain = '';
173 | $bbs = self::BIG_BLOCK_SIZE / 4;
174 | for ($i = 0; $i < $numBigBlkDepotBlks; ++$i) {
175 | $pos = ($bigBlockDepotBlocks[$i] + 1) * self::BIG_BLOCK_SIZE;
176 |
177 | $this->bigBlockChain .= substr($this->data, $pos, 4 * $bbs);
178 | $pos += 4 * $bbs;
179 | }
180 |
181 | $sbdBlock = $sbdStartBlock;
182 | $this->smallBlockChain = '';
183 | while ($sbdBlock != -2) {
184 | $pos = ($sbdBlock + 1) * self::BIG_BLOCK_SIZE;
185 |
186 | $this->smallBlockChain .= substr($this->data, $pos, 4 * $bbs);
187 | $pos += 4 * $bbs;
188 |
189 | $sbdBlock = self::getInt4d($this->bigBlockChain, $sbdBlock * 4);
190 | }
191 |
192 | // read the directory stream
193 | $block = $rootStartBlock;
194 | $this->entry = $this->readData($block);
195 |
196 | $this->readPropertySets();
197 | }
198 |
199 | /**
200 | * Extract binary stream data
201 | *
202 | * @return string
203 | */
204 | public function getStream(int $stream): ?string
205 | {
206 | $streamData = '';
207 |
208 | if ($this->props[$stream]['size'] < self::SMALL_BLOCK_THRESHOLD) {
209 | $rootdata = $this->readData($this->props[$this->rootEntry]['startBlock']);
210 |
211 | $block = $this->props[$stream]['startBlock'];
212 |
213 | while ($block != -2) {
214 | $pos = $block * self::SMALL_BLOCK_SIZE;
215 | $streamData .= substr($rootdata, $pos, self::SMALL_BLOCK_SIZE);
216 |
217 | $block = self::getInt4d($this->smallBlockChain, $block * 4);
218 | }
219 |
220 | return $streamData;
221 | }
222 |
223 | $numBlocks = $this->props[$stream]['size'] / self::BIG_BLOCK_SIZE;
224 | if ($this->props[$stream]['size'] % self::BIG_BLOCK_SIZE != 0) {
225 | ++$numBlocks;
226 | }
227 |
228 | if ($numBlocks == 0) {
229 | return '';
230 | }
231 |
232 | $block = $this->props[$stream]['startBlock'];
233 |
234 | while ($block != -2) {
235 | $pos = ($block + 1) * self::BIG_BLOCK_SIZE;
236 | $streamData .= substr($this->data, $pos, self::BIG_BLOCK_SIZE);
237 | $block = self::getInt4d($this->bigBlockChain, $block * 4);
238 | }
239 |
240 | return $streamData;
241 | }
242 |
243 | /**
244 | * Read a standard stream (by joining sectors using information from SAT)
245 | *
246 | * @param int $blID Sector ID where the stream starts
247 | *
248 | * @return string Data for standard stream
249 | */
250 | private function readData(int $blID): string
251 | {
252 | $block = $blID;
253 | $data = '';
254 |
255 | while ($block != -2) {
256 | $pos = ($block + 1) * self::BIG_BLOCK_SIZE;
257 | $data .= substr($this->data, $pos, self::BIG_BLOCK_SIZE);
258 | $block = self::getInt4d($this->bigBlockChain, $block * 4);
259 | }
260 |
261 | return $data;
262 | }
263 |
264 | /**
265 | * Read entries in the directory stream.
266 | */
267 | private function readPropertySets(): void
268 | {
269 | $offset = 0;
270 |
271 | // loop through entires, each entry is 128 bytes
272 | $entryLen = strlen($this->entry);
273 | while ($offset < $entryLen) {
274 | // entry data (128 bytes)
275 | $data = substr($this->entry, $offset, self::PROPERTY_STORAGE_BLOCK_SIZE);
276 |
277 | // size in bytes of name
278 | $nameSize = ord($data[self::SIZE_OF_NAME_POS]) | (ord($data[self::SIZE_OF_NAME_POS + 1]) << 8);
279 |
280 | // type of entry
281 | $type = ord($data[self::TYPE_POS]);
282 |
283 | // sectorID of first sector or short sector, if this entry refers to a stream (the case with workbook)
284 | // sectorID of first sector of the short-stream container stream, if this entry is root entry
285 | $startBlock = self::getInt4d($data, self::START_BLOCK_POS);
286 |
287 | $size = self::getInt4d($data, self::SIZE_POS);
288 |
289 | $name = str_replace("\x00", '', substr($data, 0, $nameSize));
290 | if ($size > 0) {
291 | $this->props[] = [
292 | 'name' => $name,
293 | 'type' => $type,
294 | 'startBlock' => $startBlock,
295 | 'size' => $size,
296 | ];
297 |
298 | // tmp helper to simplify checks
299 | $upName = strtoupper($name);
300 |
301 | switch ($upName) {
302 | case 'ROOT ENTRY':
303 | case 'R':
304 | $this->rootEntry = count($this->props) - 1;
305 | break;
306 | case chr(1) . 'COMPOBJ':
307 | break;
308 | case chr(1) . 'OLE':
309 | break;
310 | case chr(5) . 'SUMMARYINFORMATION':
311 | $this->summaryInformation = count($this->props) - 1;
312 | break;
313 | case chr(5) . 'DOCUMENTSUMMARYINFORMATION':
314 | $this->docSummaryInfos = count($this->props) - 1;
315 | break;
316 | case 'CURRENT USER':
317 | $this->currentUser = count($this->props) - 1;
318 | break;
319 | case 'PICTURES':
320 | $this->pictures = count($this->props) - 1;
321 | break;
322 | case 'POWERPOINT DOCUMENT':
323 | $this->powerpointDocument = count($this->props) - 1;
324 | break;
325 | default:
326 | throw new \Exception('OLE Block Not defined: $upName : ' . $upName . ' - $name : "' . $name . '"');
327 | }
328 | }
329 |
330 | $offset += self::PROPERTY_STORAGE_BLOCK_SIZE;
331 | }
332 | }
333 |
334 | /**
335 | * Read 4 bytes of data at specified position
336 | *
337 | * @param string $data
338 | * @param int $pos
339 | *
340 | * @return int
341 | */
342 | private static function getInt4d($data, $pos)
343 | {
344 | // FIX: represent numbers correctly on 64-bit system
345 | // http://sourceforge.net/tracker/index.php?func=detail&aid=1487372&group_id=99160&atid=623334
346 | // Hacked by Andreas Rehm 2006 to ensure correct result of the <<24 block on 32 and 64bit systems
347 | $or24 = ord($data[$pos + 3]);
348 | if ($or24 >= 128) {
349 | // negative number
350 | $ord24 = -abs((256 - $or24) << 24);
351 | } else {
352 | $ord24 = ($or24 & 127) << 24;
353 | }
354 |
355 | return ord($data[$pos]) | (ord($data[$pos + 1]) << 8) | (ord($data[$pos + 2]) << 16) | $ord24;
356 | }
357 | }
358 |
--------------------------------------------------------------------------------
/COPYING:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------