Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
35 / 35 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
Manifest | |
100.00% |
35 / 35 |
|
100.00% |
1 / 1 |
6 | |
100.00% |
1 / 1 |
write | |
100.00% |
35 / 35 |
|
100.00% |
1 / 1 |
6 |
1 | <?php |
2 | /** |
3 | * This file is part of PHPWord - A pure PHP library for reading and writing |
4 | * word processing documents. |
5 | * |
6 | * PHPWord is free software distributed under the terms of the GNU Lesser |
7 | * General Public License version 3 as published by the Free Software Foundation. |
8 | * |
9 | * For the full copyright and license information, please read the LICENSE |
10 | * file that was distributed with this source code. For the full list of |
11 | * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. |
12 | * |
13 | * @see https://github.com/PHPOffice/PHPWord |
14 | * |
15 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
16 | */ |
17 | |
18 | namespace PhpOffice\PhpWord\Writer\ODText\Part; |
19 | |
20 | use PhpOffice\PhpWord\Element\Formula; |
21 | use PhpOffice\PhpWord\Media; |
22 | use PhpOffice\PhpWord\Writer\ODText; |
23 | |
24 | /** |
25 | * ODText manifest part writer: META-INF/manifest.xml. |
26 | */ |
27 | class Manifest extends AbstractPart |
28 | { |
29 | /** |
30 | * Write part. |
31 | * |
32 | * @return string |
33 | */ |
34 | public function write() |
35 | { |
36 | $xmlWriter = $this->getXmlWriter(); |
37 | |
38 | $xmlWriter->startDocument('1.0', 'UTF-8'); |
39 | $xmlWriter->startElement('manifest:manifest'); |
40 | $xmlWriter->writeAttribute('manifest:version', '1.2'); |
41 | $xmlWriter->writeAttribute('xmlns:manifest', 'urn:oasis:names:tc:opendocument:xmlns:manifest:1.0'); |
42 | |
43 | $xmlWriter->startElement('manifest:file-entry'); |
44 | $xmlWriter->writeAttribute('manifest:media-type', 'application/vnd.oasis.opendocument.text'); |
45 | $xmlWriter->writeAttribute('manifest:full-path', '/'); |
46 | $xmlWriter->writeAttribute('manifest:version', '1.2'); |
47 | $xmlWriter->endElement(); |
48 | |
49 | // Parts |
50 | foreach (['content.xml', 'meta.xml', 'styles.xml'] as $part) { |
51 | $xmlWriter->startElement('manifest:file-entry'); |
52 | $xmlWriter->writeAttribute('manifest:media-type', 'text/xml'); |
53 | $xmlWriter->writeAttribute('manifest:full-path', $part); |
54 | $xmlWriter->endElement(); |
55 | } |
56 | |
57 | // Media files |
58 | $media = Media::getElements('section'); |
59 | foreach ($media as $medium) { |
60 | if ($medium['type'] == 'image') { |
61 | $xmlWriter->startElement('manifest:file-entry'); |
62 | $xmlWriter->writeAttribute('manifest:media-type', $medium['imageType']); |
63 | $xmlWriter->writeAttribute('manifest:full-path', 'Pictures/' . $medium['target']); |
64 | $xmlWriter->endElement(); |
65 | } |
66 | } |
67 | |
68 | foreach ($this->getObjects() as $idxObject => $object) { |
69 | if ($object instanceof Formula) { |
70 | $xmlWriter->startElement('manifest:file-entry'); |
71 | $xmlWriter->writeAttribute('manifest:full-path', 'Formula' . $idxObject . '/content.xml'); |
72 | $xmlWriter->writeAttribute('manifest:media-type', 'text/xml'); |
73 | $xmlWriter->endElement(); |
74 | $xmlWriter->startElement('manifest:file-entry'); |
75 | $xmlWriter->writeAttribute('manifest:full-path', 'Formula' . $idxObject . '/'); |
76 | $xmlWriter->writeAttribute('manifest:version', '1.2'); |
77 | $xmlWriter->writeAttribute('manifest:media-type', 'application/vnd.oasis.opendocument.formula'); |
78 | $xmlWriter->endElement(); |
79 | } |
80 | } |
81 | |
82 | $xmlWriter->endElement(); // manifest:manifest |
83 | |
84 | return $xmlWriter->getData(); |
85 | } |
86 | } |