Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
47 / 47 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| Meta | |
100.00% |
47 / 47 |
|
100.00% |
1 / 1 |
10 | |
100.00% |
1 / 1 |
| render | |
100.00% |
47 / 47 |
|
100.00% |
1 / 1 |
10 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * This file is part of PHPPresentation - A pure PHP library for reading and writing |
| 4 | * presentations documents. |
| 5 | * |
| 6 | * PHPPresentation 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/PHPPresentation/contributors. |
| 12 | * |
| 13 | * @see https://github.com/PHPOffice/PHPPresentation |
| 14 | * |
| 15 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
| 16 | */ |
| 17 | |
| 18 | declare(strict_types=1); |
| 19 | |
| 20 | namespace PhpOffice\PhpPresentation\Writer\ODPresentation; |
| 21 | |
| 22 | use PhpOffice\Common\Adapter\Zip\ZipInterface; |
| 23 | use PhpOffice\Common\XMLWriter; |
| 24 | use PhpOffice\PhpPresentation\DocumentProperties; |
| 25 | |
| 26 | class Meta extends AbstractDecoratorWriter |
| 27 | { |
| 28 | public function render(): ZipInterface |
| 29 | { |
| 30 | // Create XML writer |
| 31 | $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); |
| 32 | $objWriter->startDocument('1.0', 'UTF-8'); |
| 33 | |
| 34 | // office:document-meta |
| 35 | $objWriter->startElement('office:document-meta'); |
| 36 | $objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0'); |
| 37 | $objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink'); |
| 38 | $objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); |
| 39 | $objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0'); |
| 40 | $objWriter->writeAttribute('xmlns:presentation', 'urn:oasis:names:tc:opendocument:xmlns:presentation:1.0'); |
| 41 | $objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office'); |
| 42 | $objWriter->writeAttribute('xmlns:smil', 'urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0'); |
| 43 | $objWriter->writeAttribute('xmlns:anim', 'urn:oasis:names:tc:opendocument:xmlns:animation:1.0'); |
| 44 | $objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#'); |
| 45 | $objWriter->writeAttribute('xmlns:officeooo', 'http://openoffice.org/2009/office'); |
| 46 | $objWriter->writeAttribute('xmlns:drawooo', 'http://openoffice.org/2010/draw'); |
| 47 | $objWriter->writeAttribute('office:version', '1.2'); |
| 48 | |
| 49 | // office:meta |
| 50 | $objWriter->startElement('office:meta'); |
| 51 | |
| 52 | // dc:creator |
| 53 | $objWriter->writeElement('dc:creator', $this->getPresentation()->getDocumentProperties()->getLastModifiedBy()); |
| 54 | // dc:date |
| 55 | $objWriter->writeElement('dc:date', gmdate('Y-m-d\TH:i:s.000', $this->getPresentation()->getDocumentProperties()->getModified())); |
| 56 | // dc:description |
| 57 | $objWriter->writeElement('dc:description', $this->getPresentation()->getDocumentProperties()->getDescription()); |
| 58 | // dc:subject |
| 59 | $objWriter->writeElement('dc:subject', $this->getPresentation()->getDocumentProperties()->getSubject()); |
| 60 | // dc:title |
| 61 | $objWriter->writeElement('dc:title', $this->getPresentation()->getDocumentProperties()->getTitle()); |
| 62 | // meta:creation-date |
| 63 | $objWriter->writeElement('meta:creation-date', gmdate('Y-m-d\TH:i:s.000', $this->getPresentation()->getDocumentProperties()->getCreated())); |
| 64 | // meta:initial-creator |
| 65 | $objWriter->writeElement('meta:initial-creator', $this->getPresentation()->getDocumentProperties()->getCreator()); |
| 66 | // meta:keyword |
| 67 | $objWriter->writeElement('meta:keyword', $this->getPresentation()->getDocumentProperties()->getKeywords()); |
| 68 | |
| 69 | // meta:user-defined |
| 70 | $oDocumentProperties = $this->oPresentation->getDocumentProperties(); |
| 71 | foreach ($oDocumentProperties->getCustomProperties() as $customProperty) { |
| 72 | $propertyValue = $oDocumentProperties->getCustomPropertyValue($customProperty); |
| 73 | $propertyType = $oDocumentProperties->getCustomPropertyType($customProperty); |
| 74 | |
| 75 | $objWriter->startElement('meta:user-defined'); |
| 76 | $objWriter->writeAttribute('meta:name', $customProperty); |
| 77 | switch ($propertyType) { |
| 78 | case DocumentProperties::PROPERTY_TYPE_INTEGER: |
| 79 | case DocumentProperties::PROPERTY_TYPE_FLOAT: |
| 80 | $objWriter->writeAttribute('meta:value-type', 'float'); |
| 81 | $objWriter->writeRaw((string) $propertyValue); |
| 82 | |
| 83 | break; |
| 84 | case DocumentProperties::PROPERTY_TYPE_BOOLEAN: |
| 85 | $objWriter->writeAttribute('meta:value-type', 'boolean'); |
| 86 | $objWriter->writeRaw($propertyValue ? 'true' : 'false'); |
| 87 | |
| 88 | break; |
| 89 | case DocumentProperties::PROPERTY_TYPE_DATE: |
| 90 | $objWriter->writeAttribute('meta:value-type', 'date'); |
| 91 | $objWriter->writeRaw(date(DATE_W3C, (int) $propertyValue)); |
| 92 | |
| 93 | break; |
| 94 | case DocumentProperties::PROPERTY_TYPE_STRING: |
| 95 | case DocumentProperties::PROPERTY_TYPE_UNKNOWN: |
| 96 | default: |
| 97 | $objWriter->writeAttribute('meta:value-type', 'string'); |
| 98 | $objWriter->writeRaw((string) $propertyValue); |
| 99 | |
| 100 | break; |
| 101 | } |
| 102 | $objWriter->endElement(); |
| 103 | } |
| 104 | |
| 105 | // @todo : Where these properties are written ? |
| 106 | // $this->getPresentation()->getDocumentProperties()->getCategory() |
| 107 | // $this->getPresentation()->getDocumentProperties()->getCompany() |
| 108 | |
| 109 | $objWriter->endElement(); |
| 110 | |
| 111 | $objWriter->endElement(); |
| 112 | |
| 113 | $this->getZip()->addFromString('meta.xml', $objWriter->getData()); |
| 114 | |
| 115 | return $this->getZip(); |
| 116 | } |
| 117 | } |