/
Meta.php
100 lines (87 loc) · 4.92 KB
/
Meta.php
1
2
3
4
5
6
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
namespace PhpOffice\PhpPresentation\Writer\ODPresentation;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpPresentation\DocumentProperties;
class Meta extends AbstractDecoratorWriter
{
/**
* @return \PhpOffice\Common\Adapter\Zip\ZipInterface
*
* @throws \Exception
*/
public function render()
{
// Create XML writer
$objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
$objWriter->startDocument('1.0', 'UTF-8');
// office:document-meta
$objWriter->startElement('office:document-meta');
$objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
$objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
$objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
$objWriter->writeAttribute('xmlns:presentation', 'urn:oasis:names:tc:opendocument:xmlns:presentation:1.0');
$objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
$objWriter->writeAttribute('xmlns:smil', 'urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0');
$objWriter->writeAttribute('xmlns:anim', 'urn:oasis:names:tc:opendocument:xmlns:animation:1.0');
$objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
$objWriter->writeAttribute('xmlns:officeooo', 'http://openoffice.org/2009/office');
$objWriter->writeAttribute('xmlns:drawooo', 'http://openoffice.org/2010/draw');
$objWriter->writeAttribute('office:version', '1.2');
// office:meta
$objWriter->startElement('office:meta');
// dc:creator
$objWriter->writeElement('dc:creator', $this->getPresentation()->getDocumentProperties()->getLastModifiedBy());
// dc:date
$objWriter->writeElement('dc:date', gmdate('Y-m-d\TH:i:s.000', $this->getPresentation()->getDocumentProperties()->getModified()));
// dc:description
$objWriter->writeElement('dc:description', $this->getPresentation()->getDocumentProperties()->getDescription());
// dc:subject
$objWriter->writeElement('dc:subject', $this->getPresentation()->getDocumentProperties()->getSubject());
// dc:title
$objWriter->writeElement('dc:title', $this->getPresentation()->getDocumentProperties()->getTitle());
// meta:creation-date
$objWriter->writeElement('meta:creation-date', gmdate('Y-m-d\TH:i:s.000', $this->getPresentation()->getDocumentProperties()->getCreated()));
// meta:initial-creator
$objWriter->writeElement('meta:initial-creator', $this->getPresentation()->getDocumentProperties()->getCreator());
// meta:keyword
$objWriter->writeElement('meta:keyword', $this->getPresentation()->getDocumentProperties()->getKeywords());
// meta:user-defined
$oDocumentProperties = $this->oPresentation->getDocumentProperties();
foreach ($oDocumentProperties->getCustomProperties() as $customProperty) {
$propertyValue = $oDocumentProperties->getCustomPropertyValue($customProperty);
$propertyType = $oDocumentProperties->getCustomPropertyType($customProperty);
$objWriter->startElement('meta:user-defined');
$objWriter->writeAttribute('meta:name', $customProperty);
switch ($propertyType) {
case DocumentProperties::PROPERTY_TYPE_INTEGER:
case DocumentProperties::PROPERTY_TYPE_FLOAT:
$objWriter->writeAttribute('meta:value-type', 'float');
$objWriter->writeRaw($propertyValue);
break;
case DocumentProperties::PROPERTY_TYPE_BOOLEAN:
$objWriter->writeAttribute('meta:value-type', 'boolean');
$objWriter->writeRaw($propertyValue ? 'true' : 'false');
break;
case DocumentProperties::PROPERTY_TYPE_DATE:
$objWriter->writeAttribute('meta:value-type', 'date');
$objWriter->writeRaw(date(DATE_W3C, (int) $propertyValue));
break;
case DocumentProperties::PROPERTY_TYPE_STRING:
case DocumentProperties::PROPERTY_TYPE_UNKNOWN:
default:
$objWriter->writeAttribute('meta:value-type', 'string');
$objWriter->writeRaw($propertyValue);
break;
}
$objWriter->endElement();
}
// @todo : Where these properties are written ?
// $this->getPresentation()->getDocumentProperties()->getCategory()
// $this->getPresentation()->getDocumentProperties()->getCompany()
$objWriter->endElement();
$objWriter->endElement();
$this->getZip()->addFromString('meta.xml', $objWriter->getData());
return $this->getZip();
}
}