@@ -32,14 +32,14 @@ class Word2007 extends AbstractWriter implements WriterInterface
32
32
*
33
33
* @var array
34
34
*/
35
- private $ cTypes = array ('default ' => array (), 'override ' => array ());
35
+ private $ contentTypes = array ('default ' => array (), 'override ' => array ());
36
36
37
37
/**
38
38
* Document relationship
39
39
*
40
40
* @var array
41
41
*/
42
- private $ docRels = array ();
42
+ private $ relationships = array ();
43
43
44
44
/**
45
45
* Create new Word2007 writer
@@ -52,7 +52,7 @@ public function __construct(PhpWord $phpWord = null)
52
52
$ this ->setPhpWord ($ phpWord );
53
53
54
54
// Create parts
55
- $ parts = array ('ContentTypes ' , 'Rels ' , 'DocProps ' , 'Document ' , 'Styles ' ,
55
+ $ parts = array ('ContentTypes ' , 'RelsMain ' , 'RelsDocument ' , ' DocPropsApp ' , ' DocPropsCore ' , 'Document ' , 'Styles ' ,
56
56
'Numbering ' , 'Settings ' , 'WebSettings ' , 'Header ' , 'Footer ' , 'Footnotes ' ,
57
57
'Endnotes ' , 'FontTable ' , 'Theme ' );
58
58
foreach ($ parts as $ part ) {
@@ -81,7 +81,7 @@ public function save($filename = null)
81
81
$ objZip = $ this ->getZipArchive ($ filename );
82
82
83
83
// Content types
84
- $ this ->cTypes ['default ' ] = array (
84
+ $ this ->contentTypes ['default ' ] = array (
85
85
'rels ' => 'application/vnd.openxmlformats-package.relationships+xml ' ,
86
86
'xml ' => 'application/xml ' ,
87
87
);
@@ -92,7 +92,7 @@ public function save($filename = null)
92
92
$ this ->addFilesToPackage ($ objZip , $ sectionMedia );
93
93
$ this ->registerContentTypes ($ sectionMedia );
94
94
foreach ($ sectionMedia as $ element ) {
95
- $ this ->docRels [] = $ element ;
95
+ $ this ->relationships [] = $ element ;
96
96
}
97
97
}
98
98
@@ -112,16 +112,16 @@ public function save($filename = null)
112
112
$ this ->addNotes ($ objZip , $ rId , 'endnote ' );
113
113
114
114
// Write parts
115
- $ objZip ->addFromString ('[Content_Types].xml ' , $ this ->getWriterPart ('contenttypes ' )->writeContentTypes ( $ this -> cTypes ));
116
- $ objZip ->addFromString ('_rels/.rels ' , $ this ->getWriterPart ('rels ' )->writeMainRels ());
117
- $ objZip ->addFromString ('docProps/app.xml ' , $ this ->getWriterPart ('docprops ' )->writeDocPropsApp ( $ this -> phpWord ));
118
- $ objZip ->addFromString ('docProps/core.xml ' , $ this ->getWriterPart ('docprops ' )->writeDocPropsCore ( $ this -> phpWord ));
119
- $ objZip ->addFromString ('word/_rels/document.xml.rels ' , $ this ->getWriterPart ('rels ' )->writeDocRels ( $ this -> docRels ));
120
- $ objZip ->addFromString ('word/document.xml ' , $ this ->getWriterPart ('document ' )->writeDocument ( $ this -> phpWord ));
121
- $ objZip ->addFromString ('word/styles.xml ' , $ this ->getWriterPart ('styles ' )->writeStyles ( $ this -> phpWord ));
122
- $ objZip ->addFromString ('word/numbering.xml ' , $ this ->getWriterPart ('numbering ' )->writeNumbering ());
123
- $ objZip ->addFromString ('word/settings.xml ' , $ this ->getWriterPart ('settings ' )->writeSettings ());
124
- $ objZip ->addFromString ('word/webSettings.xml ' , $ this ->getWriterPart ('websettings ' )->writeWebSettings ());
115
+ $ objZip ->addFromString ('[Content_Types].xml ' , $ this ->getWriterPart ('contenttypes ' )->write ( ));
116
+ $ objZip ->addFromString ('_rels/.rels ' , $ this ->getWriterPart ('relsmain ' )->write ());
117
+ $ objZip ->addFromString ('docProps/app.xml ' , $ this ->getWriterPart ('docpropsapp ' )->write ( ));
118
+ $ objZip ->addFromString ('docProps/core.xml ' , $ this ->getWriterPart ('docpropscore ' )->write ( ));
119
+ $ objZip ->addFromString ('word/_rels/document.xml.rels ' , $ this ->getWriterPart ('relsdocument ' )->write ( ));
120
+ $ objZip ->addFromString ('word/document.xml ' , $ this ->getWriterPart ('document ' )->write ( ));
121
+ $ objZip ->addFromString ('word/styles.xml ' , $ this ->getWriterPart ('styles ' )->write ( ));
122
+ $ objZip ->addFromString ('word/numbering.xml ' , $ this ->getWriterPart ('numbering ' )->write ());
123
+ $ objZip ->addFromString ('word/settings.xml ' , $ this ->getWriterPart ('settings ' )->write ());
124
+ $ objZip ->addFromString ('word/webSettings.xml ' , $ this ->getWriterPart ('websettings ' )->write ());
125
125
$ objZip ->addFromString ('word/fontTable.xml ' , $ this ->getWriterPart ('fonttable ' )->write ());
126
126
$ objZip ->addFromString ('word/theme/theme1.xml ' , $ this ->getWriterPart ('theme ' )->write ());
127
127
@@ -136,6 +136,26 @@ public function save($filename = null)
136
136
}
137
137
}
138
138
139
+ /**
140
+ * Get content types
141
+ *
142
+ * @return array
143
+ */
144
+ public function getContentTypes ()
145
+ {
146
+ return $ this ->contentTypes ;
147
+ }
148
+
149
+ /**
150
+ * Get content types
151
+ *
152
+ * @return array
153
+ */
154
+ public function getRelationships ()
155
+ {
156
+ return $ this ->relationships ;
157
+ }
158
+
139
159
/**
140
160
* Add header/footer media files
141
161
*
@@ -177,8 +197,8 @@ private function addHeaderFooterContent(Section &$section, $objZip, $elmType, &$
177
197
$ elmObject ->setRelationId (++$ rId );
178
198
$ elmFile = "{$ elmType }{$ elmCount }.xml " ;
179
199
$ objZip ->addFromString ("word/ $ elmFile " , $ this ->getWriterPart ($ elmType )->$ writeFunction ($ elmObject ));
180
- $ this ->cTypes ['override ' ]["/word/ $ elmFile " ] = $ elmType ;
181
- $ this ->docRels [] = array ('target ' => $ elmFile , 'type ' => $ elmType , 'rID ' => $ rId );
200
+ $ this ->contentTypes ['override ' ]["/word/ $ elmFile " ] = $ elmType ;
201
+ $ this ->relationships [] = array ('target ' => $ elmFile , 'type ' => $ elmType , 'rID ' => $ rId );
182
202
}
183
203
}
184
204
@@ -192,8 +212,8 @@ private function addHeaderFooterContent(Section &$section, $objZip, $elmType, &$
192
212
private function addNotes ($ objZip , &$ rId , $ noteType = 'footnote ' )
193
213
{
194
214
$ noteType = ($ noteType == 'endnote ' ) ? 'endnote ' : 'footnote ' ;
195
- $ noteTypePlural = "{$ noteType }s " ;
196
- $ method = 'get ' . $ noteTypePlural ;
215
+ $ partName = "{$ noteType }s " ;
216
+ $ method = 'get ' . $ partName ;
197
217
$ collection = $ this ->phpWord ->$ method ();
198
218
199
219
// Add footnotes media files, relations, and contents
@@ -202,12 +222,12 @@ private function addNotes($objZip, &$rId, $noteType = 'footnote')
202
222
$ this ->addFilesToPackage ($ objZip , $ media );
203
223
$ this ->registerContentTypes ($ media );
204
224
if (!empty ($ media )) {
205
- $ objZip ->addFromString ("word/_rels/ {$ noteTypePlural }.xml.rels " , $ this ->getWriterPart ('rels ' )->writeMediaRels ($ media ));
225
+ $ objZip ->addFromString ("word/_rels/ {$ partName }.xml.rels " , $ this ->getWriterPart ('rels ' )->writeMediaRels ($ media ));
206
226
}
207
227
$ elements = $ collection ->getItems ();
208
- $ objZip ->addFromString ("word/ {$ noteTypePlural }.xml " , $ this ->getWriterPart ($ noteTypePlural )->write ($ elements ));
209
- $ this ->cTypes ['override ' ]["/word/ {$ noteTypePlural }.xml " ] = $ noteTypePlural ;
210
- $ this ->docRels [] = array ('target ' => "{$ noteTypePlural }.xml " , 'type ' => $ noteTypePlural , 'rID ' => ++$ rId );
228
+ $ objZip ->addFromString ("word/ {$ partName }.xml " , $ this ->getWriterPart ($ partName )->write ($ elements ));
229
+ $ this ->contentTypes ['override ' ]["/word/ {$ partName }.xml " ] = $ partName ;
230
+ $ this ->relationships [] = array ('target ' => "{$ partName }.xml " , 'type ' => $ partName , 'rID ' => ++$ rId );
211
231
}
212
232
}
213
233
@@ -222,12 +242,12 @@ private function registerContentTypes($media)
222
242
$ mediumType = $ medium ['type ' ];
223
243
if ($ mediumType == 'image ' ) {
224
244
$ extension = $ medium ['imageExtension ' ];
225
- if (!array_key_exists ($ extension , $ this ->cTypes ['default ' ])) {
226
- $ this ->cTypes ['default ' ][$ extension ] = $ medium ['imageType ' ];
245
+ if (!array_key_exists ($ extension , $ this ->contentTypes ['default ' ])) {
246
+ $ this ->contentTypes ['default ' ][$ extension ] = $ medium ['imageType ' ];
227
247
}
228
248
} elseif ($ mediumType == 'object ' ) {
229
- if (!array_key_exists ('bin ' , $ this ->cTypes ['default ' ])) {
230
- $ this ->cTypes ['default ' ]['bin ' ] = 'application/vnd.openxmlformats-officedocument.oleObject ' ;
249
+ if (!array_key_exists ('bin ' , $ this ->contentTypes ['default ' ])) {
250
+ $ this ->contentTypes ['default ' ]['bin ' ] = 'application/vnd.openxmlformats-officedocument.oleObject ' ;
231
251
}
232
252
}
233
253
}
0 commit comments