12
12
use PhpOffice \PhpWord \PhpWord ;
13
13
14
14
/**
15
- * Word2007 contenttypes part writer
15
+ * Word2007 document properties part writer
16
16
*/
17
17
class DocProps extends AbstractWriterPart
18
18
{
@@ -24,88 +24,19 @@ public function writeDocPropsApp(PhpWord $phpWord = null)
24
24
if (is_null ($ phpWord )) {
25
25
throw new Exception ("No PhpWord assigned. " );
26
26
}
27
-
28
- // Create XML writer
29
27
$ xmlWriter = $ this ->getXmlWriter ();
30
28
31
- // XML header
32
29
$ xmlWriter ->startDocument ('1.0 ' , 'UTF-8 ' , 'yes ' );
33
-
34
- // Properties
35
30
$ xmlWriter ->startElement ('Properties ' );
36
31
$ xmlWriter ->writeAttribute ('xmlns ' , 'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties ' );
37
32
$ xmlWriter ->writeAttribute ('xmlns:vt ' , 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes ' );
38
33
39
- // Application
40
- $ xmlWriter ->writeElement ('Application ' , 'Microsoft Office Word ' );
41
-
42
- // ScaleCrop
43
- $ xmlWriter ->writeElement ('ScaleCrop ' , 'false ' );
44
-
45
- // HeadingPairs
46
- $ xmlWriter ->startElement ('HeadingPairs ' );
47
-
48
- // Vector
49
- $ xmlWriter ->startElement ('vt:vector ' );
50
- $ xmlWriter ->writeAttribute ('size ' , '4 ' );
51
- $ xmlWriter ->writeAttribute ('baseType ' , 'variant ' );
52
-
53
- // Variant
54
- $ xmlWriter ->startElement ('vt:variant ' );
55
- $ xmlWriter ->writeElement ('vt:lpstr ' , 'Theme ' );
56
- $ xmlWriter ->endElement ();
57
-
58
- // Variant
59
- $ xmlWriter ->startElement ('vt:variant ' );
60
- $ xmlWriter ->writeElement ('vt:i4 ' , '1 ' );
61
- $ xmlWriter ->endElement ();
62
-
63
- // Variant
64
- $ xmlWriter ->startElement ('vt:variant ' );
65
- $ xmlWriter ->writeElement ('vt:lpstr ' , 'Slide Titles ' );
66
- $ xmlWriter ->endElement ();
67
-
68
- // Variant
69
- $ xmlWriter ->startElement ('vt:variant ' );
70
- $ xmlWriter ->writeElement ('vt:i4 ' , '1 ' );
71
- $ xmlWriter ->endElement ();
72
-
73
- $ xmlWriter ->endElement ();
74
-
75
- $ xmlWriter ->endElement ();
76
-
77
- // TitlesOfParts
78
- $ xmlWriter ->startElement ('TitlesOfParts ' );
79
-
80
- // Vector
81
- $ xmlWriter ->startElement ('vt:vector ' );
82
- $ xmlWriter ->writeAttribute ('size ' , '1 ' );
83
- $ xmlWriter ->writeAttribute ('baseType ' , 'lpstr ' );
84
-
85
- $ xmlWriter ->writeElement ('vt:lpstr ' , 'Office Theme ' );
86
-
87
- $ xmlWriter ->endElement ();
88
-
89
- $ xmlWriter ->endElement ();
90
-
91
- // Company
34
+ $ xmlWriter ->writeElement ('Application ' , 'PHPWord ' );
92
35
$ xmlWriter ->writeElement ('Company ' , $ phpWord ->getDocumentProperties ()->getCompany ());
36
+ $ xmlWriter ->writeElement ('Manager ' , $ phpWord ->getDocumentProperties ()->getManager ());
93
37
94
- // LinksUpToDate
95
- $ xmlWriter ->writeElement ('LinksUpToDate ' , 'false ' );
96
-
97
- // SharedDoc
98
- $ xmlWriter ->writeElement ('SharedDoc ' , 'false ' );
38
+ $ xmlWriter ->endElement (); // Properties
99
39
100
- // HyperlinksChanged
101
- $ xmlWriter ->writeElement ('HyperlinksChanged ' , 'false ' );
102
-
103
- // AppVersion
104
- $ xmlWriter ->writeElement ('AppVersion ' , '12.0000 ' );
105
-
106
- $ xmlWriter ->endElement ();
107
-
108
- // Return
109
40
return $ xmlWriter ->getData ();
110
41
}
111
42
@@ -117,24 +48,25 @@ public function writeDocPropsApp(PhpWord $phpWord = null)
117
48
*/
118
49
public function writeDocPropsCore (PhpWord $ phpWord )
119
50
{
120
- // Create XML writer
51
+ if (is_null ($ phpWord )) {
52
+ throw new Exception ("No PhpWord assigned. " );
53
+ }
121
54
$ xmlWriter = $ this ->getXmlWriter ();
122
55
123
- // XML header
124
56
$ xmlWriter ->startDocument ('1.0 ' , 'UTF-8 ' , 'yes ' );
125
-
126
- // cp:coreProperties
127
57
$ xmlWriter ->startElement ('cp:coreProperties ' );
128
58
$ xmlWriter ->writeAttribute ('xmlns:cp ' , 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties ' );
129
59
$ xmlWriter ->writeAttribute ('xmlns:dc ' , 'http://purl.org/dc/elements/1.1/ ' );
130
60
$ xmlWriter ->writeAttribute ('xmlns:dcterms ' , 'http://purl.org/dc/terms/ ' );
131
61
$ xmlWriter ->writeAttribute ('xmlns:dcmitype ' , 'http://purl.org/dc/dcmitype/ ' );
132
62
$ xmlWriter ->writeAttribute ('xmlns:xsi ' , 'http://www.w3.org/2001/XMLSchema-instance ' );
133
63
134
- // dc:creator
135
64
$ xmlWriter ->writeElement ('dc:creator ' , $ phpWord ->getDocumentProperties ()->getCreator ());
136
-
137
- // cp:lastModifiedBy
65
+ $ xmlWriter ->writeElement ('dc:title ' , $ phpWord ->getDocumentProperties ()->getTitle ());
66
+ $ xmlWriter ->writeElement ('dc:description ' , $ phpWord ->getDocumentProperties ()->getDescription ());
67
+ $ xmlWriter ->writeElement ('dc:subject ' , $ phpWord ->getDocumentProperties ()->getSubject ());
68
+ $ xmlWriter ->writeElement ('cp:keywords ' , $ phpWord ->getDocumentProperties ()->getKeywords ());
69
+ $ xmlWriter ->writeElement ('cp:category ' , $ phpWord ->getDocumentProperties ()->getCategory ());
138
70
$ xmlWriter ->writeElement ('cp:lastModifiedBy ' , $ phpWord ->getDocumentProperties ()->getLastModifiedBy ());
139
71
140
72
// dcterms:created
@@ -149,24 +81,8 @@ public function writeDocPropsCore(PhpWord $phpWord)
149
81
$ xmlWriter ->writeRaw (date (DATE_W3C , $ phpWord ->getDocumentProperties ()->getModified ()));
150
82
$ xmlWriter ->endElement ();
151
83
152
- // dc:title
153
- $ xmlWriter ->writeElement ('dc:title ' , $ phpWord ->getDocumentProperties ()->getTitle ());
154
-
155
- // dc:description
156
- $ xmlWriter ->writeElement ('dc:description ' , $ phpWord ->getDocumentProperties ()->getDescription ());
157
-
158
- // dc:subject
159
- $ xmlWriter ->writeElement ('dc:subject ' , $ phpWord ->getDocumentProperties ()->getSubject ());
160
-
161
- // cp:keywords
162
- $ xmlWriter ->writeElement ('cp:keywords ' , $ phpWord ->getDocumentProperties ()->getKeywords ());
163
-
164
- // cp:category
165
- $ xmlWriter ->writeElement ('cp:category ' , $ phpWord ->getDocumentProperties ()->getCategory ());
166
-
167
- $ xmlWriter ->endElement ();
84
+ $ xmlWriter ->endElement (); // cp:coreProperties
168
85
169
- // Return
170
86
return $ xmlWriter ->getData ();
171
87
}
172
88
}
0 commit comments